csu 1550(字符串处理思路题)
1550: Simple String
Time Limit: 1 Sec Memory Limit: 256 MB
Submit: 481 Solved: 211
[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
- 题意:给出3个串A B C,长度都为 2*n ,能否在 A 中选n个字符,在B中选n个字符,组成C?
题解:我们将A串作为基准串 ,A中每个字符能够选的最少数量为 max(0,num2[i]-num1[i]) ,能够选的最多数量为 min(num[i],num2[i]) ,将所有的可能相加,如果 n 在这个范围内,那么我们就一定可以在B中选出长度为n的串组成C。
- #include<stdio.h>
- #include<iostream>
- #include<string.h>
- #include<math.h>
- #include<algorithm>
- using namespace std;
- const int N = ;
- char A[N],B[N],C[N];
- int num[],num1[],num2[];
- int main()
- {
- while(scanf("%s",A)!=EOF){
- scanf("%s",B);
- scanf("%s",C);
- int len = strlen(A);
- memset(num,,sizeof(num));
- memset(num1,,sizeof(num1));
- memset(num2,,sizeof(num2));
- for(int i=;i<len;i++){
- num[A[i]-'A']++;
- num1[B[i]-'A']++;
- num2[C[i]-'A']++;
- }
- bool flag = true;
- int l = ,r = ;
- for(int i=;i<;i++){
- if(num[i]+num1[i]<num2[i]){ ///第三个串中某个字符数量 > 一串和二串之和
- flag = false;
- break;
- }
- int MIN = max(,num2[i]-num1[i]); ///最少可以贡献的字符数量
- int MAX = min(num[i],num2[i]); ///最多可以贡献的字符数量
- l+=MIN;
- r+=MAX;
- }
- if(!(l<=len/&&r>=len/)) flag = false;
- if(!flag) printf("NO\n");
- else printf("YES\n");
- }
- return ;
- }
csu 1550(字符串处理思路题)的更多相关文章
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
- POJ 1904 思路题
思路: 思路题 题目诡异地给了一组可行匹配 肯定有用啊-. 就把那组可行的解 女向男连一条有向边 如果男喜欢女 男向女连一条有向边 跑一边Tarjan就行了 (这个时候 环里的都能选 "增广 ...
- BZOJ 3252: 攻略(思路题)
传送门 解题思路 比较好想的一道思路题,结果有个地方没开\(long\) \(long\) \(wa\)了三次..其实就是模仿一下树链剖分,重新定义重儿子,一个点的重儿子为所有儿子中到叶节点权值最大的 ...
- BZOJ 1303: [CQOI2009]中位数图(思路题)
传送门 解题思路 比较好想的思路题.首先肯定要把原序列转化一下,大于\(k\)的变成\(1\),小于\(k\)的变成\(-1\),然后求一个前缀和,还要用\(cnt[]\)记录一下前缀和每个数出现了几 ...
- CSU - 1550 Simple String —— 字符串
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 题解: 1.A+B 与C的交集必须>=n 2.A与C的交集必须>= ...
- Water --- CSU 1550: Simple String
Simple String Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...
- D - Simple String CSU - 1550
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz, 但是这题只需要简 ...
- csu 1554: SG Value 思维题
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!! 先不考虑插入操作, ...
随机推荐
- 测试开发面试的Linux面试题总结之二:常用命令
(1)Linux的文件系统目录配置要遵循FHS规范,规范定义的两级目录规范如下: /home 每个账号在该目录下都有一个文件夹,进行数据的管理 /usr 有点像windo ...
- 使图片相对于上层DIV始终水平、垂直都居中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- max os取消开机启动
原文:http://liuzhichao.com/p/1667.html 安装MAMP后,启动服务时提示Apache启动失败,80端口被占用.查看进程发现存在几个httpd. OS X自带Apache ...
- [JOI 2014 Final] IOI 馒头
link 试题分析 我们发现若是要选馒头的话则应该从馒头售价高的先装. 并且若要选择包装盒时应该选择装x个最小的时候.所以只需要贪心$+$背包即可. #include<iostream> ...
- html中的事件属性
Window 事件属性 针对 window 对象触发的事件(应用到 <body> 标签): 属性 值 描述 onafterprint script 文档打印之后运行的脚本. onbefor ...
- codeforces 691E 矩阵快速幂+dp
传送门:https://codeforces.com/contest/691/problem/E 题意:给定长度为n的序列,从序列中选择k个数(可以重复选择),使得得到的排列满足xi与xi+1异或的二 ...
- $('.goods_tag_ids_all')[0].checked = true;//~~~~~ 单条改变checkbox 属性样式
//点击左边全选选中时,都全选$('.goods_tag_ids_all').on('click',function(){ if($('.goods_tag_ids_all').is(':checke ...
- SDK代码记录
zynq中SDK相关API的学习.记录常用函数 /*************************************************************************** ...
- Bootstrap笔记-加强版
1.bootstrap引入: <!DOCTYPE html><html lang="zh-cn"><head><meta charset= ...
- 【VSCode】Windows下VSCode编译调试c/c++【更新 2018.03.27】
--------– 2018.03.27 更新--------- 便携版已更新,点此获取便携版 已知BUG:中文目录无法正常调试 用于cpptools 0.15.0插件的配置文件更新 新的launch ...