1550: Simple String
Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 460 Solved: 200
[ Submit][ Status][ Web Board]
Description
Welcome,this is the 2015 3th Multiple Universities Programming Contest ,Changsha ,Hunan Province. In order to let you feel fun, ACgege will give you a simple problem. But is that true? OK, let’s enjoy it.
There are three strings A , B and C. The length of the string A is 2*N, and the length of the string B and C is same to A. You can take N characters from A and take N characters from B. Can you set them to C ?
Input
There are several test cases.
Each test case contains three lines A,B,C. They only contain upper case letter.
0<N<100000
The input will finish with the end of file.
Output
For each the case, if you can get C, please print “YES”. If you cann’t get C, please print “NO”.
Sample Input
AABB
BBCC
AACC
AAAA
BBBB
AAAA
Sample Output
YES
NO
思路:
这题我个人感觉是固定一个串(a)来构造另外一个串(b),所以只要讨论b时,a就随着b的变化而变化吧。
AC代码:
#include<iostream> #include<algorithm> #include<cstring> #include<string> #include<cstdio> #include<queue> using namespace std; #define T 100050 int v[3][30]; char a[T*2],b[T*2],c[T*2]; bool ok() { int len = strlen(a),ma=0,mi=0; for(int i=0;i<26;++i){ //两个串的当前字母的和小于目标的大小,不能构成目标串 if(v[0][i]+v[1][i]<v[2][i])return false; //b串最小要用多少字母 mi += max(0,v[2][i]-v[0][i]); //b串最多要用多少字母 ma += min(v[2][i],v[1][i]); } //在[mi,ma]范围内必须要找到len/2才能构成c串 if(ma>=len/2&&mi<=len/2)return true; return false; } int main() { #ifdef zsc freopen("input.txt","r",stdin); #endif int i; while(~scanf("%s",&a)) { scanf("%s%s",&b,&c); memset(v,0,sizeof(v)); for(i=0;a[i];++i){ v[0][a[i]-'A']++; v[1][b[i]-'A']++; v[2][c[i]-'A']++; } if(ok()==false)printf("NO\n"); else printf("YES\n"); } return 0; }
1550: Simple String
Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 460 Solved: 200
[ Submit][ Status][ Web Board]
Description
Welcome,this is the 2015 3th Multiple Universities Programming Contest ,Changsha ,Hunan Province. In order to let you feel fun, ACgege will give you a simple problem. But is that true? OK, let’s enjoy it.
There are three strings A , B and C. The length of the string A is 2*N, and the length of the string B and C is same to A. You can take N characters from A and take N characters from B. Can you set them to C ?
Input
There are several test cases.
Each test case contains three lines A,B,C. They only contain upper case letter.
0<N<100000
The input will finish with the end of file.
Output
For each the case, if you can get C, please print “YES”. If you cann’t get C, please print “NO”.
Sample Input
AABB
BBCC
AACC
AAAA
BBBB
AAAA
Sample Output
YES
NO