1550: Simple String (做得少的思维题,两个字符串能否组成另外一个字符串问题)
1550: Simple String
Submit Page Summary Time Limit: 1 Sec Memory Limit: 256 Mb Submitted: 682 Solved: 287
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
Hint
Source
给你三个字符串
a,b,c
长度都是2*n
问你从a和b中各抽出n给字符
能不能组成c
统计a,b,c中26个字符出现的次数
如果某字符在a中出现次数+在b中出现次数小于该字符在c中出现次数
那么肯定不能组成c
1.A+B 与C的交集必须>=n
2.A与C的交集必须>=n/2,B与C的交集必须>=n/2。
理解上面两句话就可以了
#include<stdio.h>
#include<iostream>
#include<vector>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include<string>
#include<string.h>
#include<math.h>
typedef long long LL;
using namespace std;
#define max_v 125
int c1[];
int c2[];
int c3[];
void init()
{
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
memset(c3,,sizeof(c3));
}
int main()
{
string str1,str2,str3;
while(cin>>str1)
{
init();
cin>>str2;
cin>>str3;
int l=str1.length();
for(int i=; i<l; i++)
{
c1[str1[i]-'A']++;
c2[str2[i]-'A']++;
c3[str3[i]-'A']++;
}
int flag=;
int v1=;
int v2=;
for(int i=; i<; i++)
{
if(c1[i]+c2[i]<c3[i])
{
flag=;
break;
}
v1+=max(,c3[i]-c1[i]);
v2+=min(c3[i],c2[i]);
}
if(v2<l/||v1>l/)
flag=;
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
/*
题目意思:
给你三个字符串
a,b,c
长度都是2*n
问你从a和b中各抽出n给字符
能不能组成c 分析:
统计a,b,c中26个字符出现的次数
如果某字符在a中出现次数+在b中出现次数小于该字符在c中出现次数
那么肯定不能组成c
1.A+B 与C的交集必须>=n
2.A与C的交集必须>=n/2,B与C的交集必须>=n/2。
理解上面两句话就可以了 */
1550: Simple String (做得少的思维题,两个字符串能否组成另外一个字符串问题)的更多相关文章
- Water --- CSU 1550: Simple String
Simple String Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...
- 1550: Simple String 最大流解法
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 很久以前做的一题,当时队友用最大流做,现在我也是 这个转化为二分图多重匹配,就是一样的意 ...
- CSU - 1550 Simple String —— 字符串
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550 题解: 1.A+B 与C的交集必须>=n 2.A与C的交集必须>= ...
- Jumbled String (Kattis - jumbledstring)(思维题)
Problem Recall that a subsequence of a string is any string obtained by removing some subset of char ...
- little w and Soda(思维题)
链接:https://ac.nowcoder.com/acm/contest/297/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- UVA.11464 Even Parity (思维题 开关问题)
UVA.11464 Even Parity (思维题 开关问题) 题目大意 给出一个n*n的01方格,现在要求将其中的一些0转换为1,使得每个方格的上下左右格子的数字和为偶数(如果存在的话),求使得最 ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- (比赛)A - Simple String Problem
A - Simple String Problem Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%lld & ...
随机推荐
- 移动web模拟客户端实现多方框输入密码效果
不知道怎么描述标题,先看截图吧,大致的效果就是一个框输入一位密码. 最开始实现的思路是一个小方框就是一个type为password的input,每输入一位自动跳到下一位,删除一位就自动跳到前一位,an ...
- CSS-带尖角的对话框
效果图: box1的代码: .box{ position: relative; width: 200px; height: 200px; border: 2px solid #000; backgro ...
- html-使用表单标签实现注册页面
案例说明: - 使用表格实现页面效果 - 超链接不想要有效果,使用href="#" - 如果表格里面的单元格没有内容,使用空格作为占位符 - 使用图片标签提交表单 <in ...
- [微信小程序] 微信小程序富文本-wxParse的使用
最近小程序蛮火的,公司要做于是学了一点点小程序 不知道你们有没有遇到过这种问题: 从公司服务器获取的文章内容是有HTML标签格式的一段内容,但是微信是不支持这些标签的,怎么办呢? 1.一般网站后台的文 ...
- [WEB地图] 2017高德地图API WEB开发(key申请,地图搭建)简约教程
前端时间因为公司需要研究 了一下百度的教程 然后写个简约的笔记记录一下自己学习的收获,只为了满足自己暂时的写作热情 高德地图WEB开发(key申请.api)简约教程 1.首先我们需要去“高德地 ...
- Mac终端使用技巧 切换到其他路径和目录
如果你想将当前 command line 会话切换到其他目录,需要用到三个命令:pwd,ls和cd. pwd的含义是“print working directory”,会显示当前目录的绝对路径. ls ...
- Application Context的设计
基本上每一个应用程序都会有一个自己的Application,并让它继承自系统的Application类,然后在自己的Application类中去封装一些通用的操作.其实这并不是Google所推荐的一种 ...
- Linux 安装MySQL-python
vi ~/.bash_profile PATH="/usr/local/mysql/bin:${PATH}" export PATH export DYLD_LIBRARY_PAT ...
- 精华阅读第 12 期 | 最新 App Store 审核指南与10大被拒理由?
很多时候,我们对技术的追求是没有止境的,我们需要不断的学习,进步,再学习,再进步!本文系移动精英开发俱乐部的第12期文章推荐阅读整理,其中涉及到了 Android 数据库框架,架构设计中的循环引用,同 ...
- STL中 vector 和 list 一些特性
STL中的vector特点是: 其容量在需要时可以自动分配,本质上是数组形式的存储方式.即在索引可以在常数时间内完成.缺点是在插入或者删除一项时,需要线性时间.但是在尾部插入或者删除,是常数时间的. ...