跳过正文
  1. Posts/

(BC 一周年)hdu 5311 Hidden String

·2 分钟

http://acm.hdu.edu.cn/showproblem.php?pid=5311 题意:问能否从一个给定的字符串中拿出三个不相交的字串(原串可以有剩余),组成字符串“anniversary” 思路:暴力。

比赛的时候没做出来,sad 我发现我有一个问题,就是不敢跑暴力 有不少题其实正解就是暴力 或者有的题,暴力不是标解,但是绝对可A,可我就不敢写… 就觉得不会是这样.. 说到底还是不自信吧…

思路是枚举两个间隔点,将 string tar=“anniversary"分成三个不为空的部分 然后在给的字符串中按顺序查找这三部分 如果都能找到,直接YES 如果任何一种间隔的分段都无法YES 就NO…

妈蛋,if语句后面多写了个分号,调了半个多小时才发现(为啥总是这种傻逼错误….) 还有一点,因为是多组数据,而对于每组数据,将tar拆分的方法都是一样的,可以先预处理一下存到数组里.

  1
  2   #define yn hez111qqz
  3   #define j1 cute111qqz
  4   #define tm crazy111qqz
  5   #define lr dying111qqz
  6   using namespace std;
  7   #define REP(i, n) for (int i=0;i<int(n);++i)
  8   typedef long long LL;
  9   typedef unsigned long long ULL;
 10   const int N=1E2+5;
 11   int d[N];
 12   int len;
 13   string st,tar,s1,s2,s3;
 14   bool flag;
 15
 16   void solve (string x,string y,string z)
 17   {
 18       int lx = x.length();
 19       int ly = y.length();
 20       int lz = z.length();
 21       bool debug = false;
 22       if (x=="anniv"&&y=="er"&&z=="sary")
 23   	debug = true;
 24       int p;
 25       int k = 0;
 26       for ( int i = 0 ; i  < len-lx+1 ; i++ )
 27       {
 28   	string tmps = st.substr(i,lx);
 29   //	if (debug) cout<<"tmaaaps:"<<tmps<<endl;
 30   	if (tmps==x);
 31   	{
 32   	    p = i;
 33   	   // cout<<"tmps1:"<<tmps<<endl;
 34   	    k++;
 35   	    break;
 36   	}
 37       }
 38       if (k==0) return;
 39
 40       for ( int i =  p+lx ;  i < len - ly +1 ;i++)
 41       {
 42   	string tmps = st.substr(i,ly);
 43       //	if (debug) cout<<"tms2:"<<tmps<<endl;
 44   	if (tmps==y)
 45   	{
 46   	    p = i ;
 47   	  //  cout<<"tmps2:"<<tmps<<endl;
 48   	    k++;
 49   	    break;
 50   	}
 51       }
 52       if (k==1) return ;
 53       for ( int i = p+ly;  i < len - lz +1 ; i ++)
 54       {
 55   	string tmps = st.substr(i,lz);
 56   	if (tmps==z)
 57   	{
 58   	//    cout<<"tmps3:"<<tmps<<endl;
 59   	    k++;
 60   	    break;
 61   	}
 62       }
 63       if (k==3)
 64       {
 65   	flag = true;
 66   	return;
 67       }
 68
 69   }
 70   int main()
 71   {
 72       int T;
 73       cin>>T;
 74       while (T--)
 75       {
 76   	  flag = false;
 77   	  cin>>st;
 78   	  len = st.length();
 79   	  int k = 0;
 80   	  int num = 0;
 81   	  tar="anniversary";
 82   	  for ( int i = 1 ; i <=9 ;  i++ )
 83   	  {
 84   	    for ( int j = i+1 ; j <= 10 ; j++ )
 85   		{
 86   		    s1 = tar.substr(0,i);
 87   		    s2 = tar.substr(i,j-i);
 88   		    s3 = tar.substr(j);
 89   		 //   cout<<i<<" "<<j<<" "<<s1<<" "<<s2<<" "<<s3<<endl;
 90   		    solve (s1,s2,s3);
 91   		    if (flag)
 92   		    {
 93   			break;
 94   		    }
 95   		}
 96   	    if (flag)
 97   		break;
 98   	  }
 99   	  if (flag)
100   	    {
101   		cout<<"YES"<<endl;
102   	    }
103   	  else
104   	    {
105   		cout<<"NO"<<endl;
106   	    }
107
108       }
109
110   	return 0;
111   }

相关文章

poj 3279 Fliptile (搜索..暴力?)

·2 分钟
http://poj.org/problem?id=3279 反转类问题. 有N*M个方格,每个上面有数字0或者1 操作一个方格,这个方格即其相邻的四个方格(有公共边)会改变状态(由0变1或者由1变0)

codeforces 548B Mike and Fun

·1 分钟
http://codeforces.com/problemset/problem/548/B 比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。

(BC 一周年)hdu 5310 Souvenir

·1 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=5310 水。 不要用cin. 1 2 /************************************************************************* 3 > File Name: code/bc/#ann/1001.cpp 4 > Author: 111qqz 5 > Email: rkz2013@126.com 6 > Created Time: 2015年07月25日 星期六 18时54分24秒 7 ************************************************************************/ 8 9 #include<iostream> 10 #include<iomanip> 11 #include<cstdio> 12 #include<algorithm> 13 #include<cmath> 14 #include<cstring> 15 #include<string> 16 #include<map> 17 #include<set> 18 #include<queue> 19 #include<vector> 20 #include<stack> 21 #define y0 abc111qqz 22 #define y1 hust111qqz 23 #define yn hez111qqz 24 #define j1 cute111qqz 25 #define tm crazy111qqz 26 #define lr dying111qqz 27 using namespace std; 28 #define REP(i, n) for (int i=0;i<int(n);++i) 29 typedef long long LL; 30 typedef unsigned long long ULL; 31 int n,m,p,q; 32 int main() 33 { 34 int T; 35 cin>>T; 36 int ans = 0; 37 while (T--) 38 { 39 // scanf("%d %d %d %d",&n,&m,&p,&q); 40 scanf("%d %d %d %d",&n,&m,&p,&q); 41 ans = n*p; 42 ans = min(ans,n/m*q+n%m*p); 43 ans = min(ans,((n-1)/m+1)*q); 44 printf("%d\n",ans); 45 } 46 47 return 0; 48 }

uva 12442 . Forwarding Emails

·2 分钟
“… so forward this to ten other people, to prove that you believe the emperor has 题意是说发短信,每个人只会给一个人发,问从哪个人开始发,能传到的人最多