CSU 1550-Simple String(字符串)

来源:互联网 发布:怎么开企业淘宝店铺 编辑:程序博客网 时间:2024/05/15 10:08


1550: Simple String

Time Limit: 1 Sec  Memory Limit: 256 MB
Submit: 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

AABBBBCCAACCAAAABBBBAAAA

Sample Output

YESNO
思路:
    这题我个人感觉是固定一个串(a)来构造另外一个串(b),所以只要讨论b时,a就随着b的变化而变化吧。
AC代码:
#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cstdio>#include<queue>using namespace std;#define T 100050int 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 zscfreopen("input.txt","r",stdin);#endifint 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 MB
Submit: 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

AABBBBCCAACCAAAABBBBAAAA

Sample Output

YESNO
0 0
原创粉丝点击