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(字符串处理思路题)的更多相关文章

  1. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

  2. 51nod P1305 Pairwise Sum and Divide ——思路题

    久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...

  3. POJ 1904 思路题

    思路: 思路题 题目诡异地给了一组可行匹配 肯定有用啊-. 就把那组可行的解 女向男连一条有向边 如果男喜欢女 男向女连一条有向边 跑一边Tarjan就行了 (这个时候 环里的都能选 "增广 ...

  4. BZOJ 3252: 攻略(思路题)

    传送门 解题思路 比较好想的一道思路题,结果有个地方没开\(long\) \(long\) \(wa\)了三次..其实就是模仿一下树链剖分,重新定义重儿子,一个点的重儿子为所有儿子中到叶节点权值最大的 ...

  5. BZOJ 1303: [CQOI2009]中位数图(思路题)

    传送门 解题思路 比较好想的思路题.首先肯定要把原序列转化一下,大于\(k\)的变成\(1\),小于\(k\)的变成\(-1\),然后求一个前缀和,还要用\(cnt[]\)记录一下前缀和每个数出现了几 ...

  6. CSU - 1550 Simple String —— 字符串

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 题解: 1.A+B 与C的交集必须>=n 2.A与C的交集必须>= ...

  7. Water --- CSU 1550: Simple String

    Simple String Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...

  8. D - Simple String CSU - 1550

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz, 但是这题只需要简 ...

  9. csu 1554: SG Value 思维题

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!! 先不考虑插入操作, ...

随机推荐

  1. Linux系统启动详解(一)

    本篇主要以Centos为例,讲述整个Linux系统启动过程,包括了grub引导,initramfs流程,/sbin/init执行rc.sysinit及rc的大体流程. 另外,本篇有一个实例来说明,将整 ...

  2. 解题:POI 2007 Weights

    题面 这是个$O(nlog^2$ $n)$的解法,因为蒟蒻博主没有看懂$O(nlog$ $n)$的更优秀的解法 显然从小到大装砝码是最优的方法,又显然从大到小装容器不会使得答案变劣,还显然砝码数具有单 ...

  3. [POI2011]SEJ-Strongbox

    题目大意: 一个有密码箱,数字是0~n-1,其中有若干个密码,密码的特点:若x是密码,y是密码,(x可以等于y)则(x+y)%n也是密码. 给一个n(<=10^14),一个k(k<=min ...

  4. 【CF601C】Kleofáš and the n-thlon

    Portal -->CF601C Description 大概是说\(m\)个人参加\(n\)场比赛,每场一人有一个排名,每场没有两个人排名相同,一个人最后的得分是\(n\)场比赛的排名相加,现 ...

  5. Tornado----自定义异步非阻塞Web框架:Snow

    Python的Web框架中Tornado以异步非阻塞而闻名.本篇将使用200行代码完成一个微型异步非阻塞Web框架:Snow. 一.源码 本文基于非阻塞的Socket以及IO多路复用从而实现异步非阻塞 ...

  6. Python3 字典 pop() 方法

     Python3 字典 描述 Python 字典 pop() 方法删除字典给定键 key 所对应的值,返回值为被删除的值.key值必须给出. 否则,返回default值. 语法 pop()方法语法: ...

  7. SSH 阿里云服务器

    1.在服务机上操作 创建要远程登录的用户和密码 sudo adduser username    正在添加用户“username”... 正在添加新组“username”(1001)... 正在添加新 ...

  8. mac 的全文搜索

    grep -Rni "view.proptypes.style" *  需要切换到要搜索的目录在运行

  9. laravel5.1 关联模型保存的方法(使用associate方法)

    模型定义 class User { public function customer() { return $this->hasOne('Customer'); } } class Custom ...

  10. Android通过php插入查询SQL数据库

    PHP代码 <?php header("Content-type: text/html; charset=gb2312"); $serverName = "loca ...