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 & ...
随机推荐
- Fastify 系列教程二 (中间件、钩子函数和装饰器)
Fastify 系列教程: Fastify 系列教程一 (路由和日志) Fastify 系列教程二 (中间件.钩子函数和装饰器) Fastify 系列教程三 (验证.序列化和生命周期) Fastify ...
- Eclipse工程 导入 Android Studio
最近Eclipse好多项目转Android Studio 百度翻看好多文章 这篇不错 特纪录下 地址:http://www.cnblogs.com/bluestorm/p/3757402.html 一 ...
- ASP.Net与JSP如何共享Session值
思路: ASP.NET中序列化Session以二进制数据保存到数据库,然后由JSP读取数据库中的二进制数据反序列化成Session对象,再强制转化成JAVA的Session对象登录的ASPX文件 ...
- 一种特殊场景下的HASH JOIN的优化为NEST LOOP.
应用场景: 有如下的SQL: select t.*, t1.ownerfrom t, t1where t.id=t1.id; 表t ,t1的数据量比较大,比如200W行.但是两张表能关联的行数却很少, ...
- I/O复用及epoll基础知识
IO multiplexing IO multiplexing这个词可能有点陌生,但是如果我说select,epoll,大概就都能明白了.有些地方也称这种IO方式为event driven IO.我们 ...
- .net 下使用Quartz.Net
Quartz.net是作业调度框架 1. 项目中添加quartz.net的引用(这里使用nuget管理) 新建一个类TimingJob,该类主要用于实现任务逻辑 using Quartz; using ...
- [SQL Server]SQL行转列
SELECT * FROM (select ActionTargetType+actiontype as TypeResult, COUNT(RowGuid) as Number from BanJi ...
- Git修改子模块的路径
Git在两个地方存储有关子模块的信息.第一个是在一个名为的文件中.gitmodules,该文件被签入git存储库.对此文件的更改将传播到其他存储库. 另一个位置在.git/config,并且它是执行大 ...
- Celery学习---Celery 分布式队列介绍及安装
Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celery, ...
- windows server 2016 无法联网问题
首先,联网分解为两个问题,一.WLAN(无线网).二.以太网(有线网) 一 .WLAN问题解决方案 1.打开服务器管理器 2.添加角色和功能 3.一直点下一步到“功能”,勾选 DirectPlay 和 ...