CSU 1550-Simple String(字符串)



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

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 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

AABB
BBCC
AACC
AAAA
BBBB
AAAA

Sample Output

YES
NO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值