CSU 1550-Simple String(字符串)
来源:互联网 发布:怎么开企业淘宝店铺 编辑:程序博客网 时间:2024/05/15 10:08
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
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 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
AABBBBCCAACCAAAABBBBAAAA
Sample Output
YESNO
- csu 1550: Simple String (字符串)
- CSU 1550-Simple String(字符串)
- ACM--字符串--CSU--1550-- Simple String
- Water --- CSU 1550: Simple String
- CSU 1716(字符串)
- CSU 1019: Simple Line Editor(模拟)
- CSU 1080: A simple maze
- Simple Line Editor----CSU 1019
- CSU---D: Simple Line Editor
- Redis源码学习——简单动态字符串SDS(Simple Dynamic String)
- csu 1716 Morse(模拟,字符串处理)
- Redis的简单动态字符串——Simple Dynamic String
- hihocoder1385 A Simple Job JAVA String split 字符串切割
- CSU - 1158 取字符串
- csu 1510 Happy Robot(字符串DP,记忆化搜索)
- CSU-1783: 聊天止于呵呵(字符串处理)
- CSU 1536 bit string reordering
- Simple String Compression Functions
- 黑马程序员——OC之NSArray、NSDictionary
- Matlab 2012b--64bit安装教程
- java解惑--谜题5:十六进制的趣事
- BZOJ 1954 (POJ 3764) Trie的经典应用 求树上最大异或值
- 使用 DownloadManager 实现完全在后台下载
- CSU 1550-Simple String(字符串)
- A+B=X
- ThinkPHP中initialize和construct的不同
- style/Theme.NoTitleBar崩溃
- sql语句
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
- Codeforces Round #335 (Div. 2) 605A Sorting Railway Cars
- Python模块学习系列(3)----Scikit Learn(机器学习库)
- 有关spring mvc精准绑定