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 & ...
随机推荐
- vue-video监听touch事件
vue-video是基于 Vue 的简洁 HTML5 视频播放器组件,但是并没有监听touch事件,也就是说在移动端按键无效. 本文讲述如何改写其vue组件,使其兼容移动端.只需要在其原有的mouse ...
- Spring是什么、spring容器、Spring三大核心思想DI(依赖注入)、IOC(控制反转)、AOP(面向切面编程)
1.Spring (1)Spring是什么? 是一个轻量级的.用来简化企业级应用开发的开发框架. 注: a.简化开发: Spring对常用的api做了简化,比如,使用Spring jdbc来访问数据库 ...
- Vue2.0项目打包后只能访问首页,其他页面路径错误找不到
原因是你使用了vue-router的history,可以尝试去掉 // mode:"history",
- iTem2 保持连接,解决ssh的"Write failed: Broken pipe"问题
方法一: profiles -> sessions -> When idel, send ASCII code 问题场景 服务器环境:阿里云 Linux CentOS 主机 客户端:Mac ...
- Python 利用Python编写简单网络爬虫实例2
利用Python编写简单网络爬虫实例2 by:授客 QQ:1033553122 实验环境 python版本:3.3.5(2.7下报错 实验目的 获取目标网站“http://www.51testing. ...
- Object.defineProperty 与数据绑定的简单实现
对象是一个属性集合,对象的基本特征是属性名(name)和属性值(value).ES5 增加了属性描述符,包括数据属性描述符(configurable enumerable writable value ...
- redis 命令select、dbsize、清空数据库、info、client
select 切换库 dbsize 当前库中数据条数 清空数据库 flushdb | flushall 清空数据,一个是清空当前库,一个清空当前实例 查看服务器及redis相关信息 infoinfo ...
- OpenStreetMap、googleMap等经纬度和行列号之间相互转化(python,JavaScript,php,Java,C#等)
python: # OpenStreetMap经纬度转行列号 def deg2num(lat_deg, lon_deg, zoom): lat_rad = math.radians(lat_deg) ...
- Sql Server tempdb原理-启动过程解析实践
我们知道在SqlServer实例启动过程中数据库会进行还原(Redo,Undo)然后打开提供服务,但我们知道tempdb是不提供重做机制的(Redo)那tempdb是如何还原的呢?如果tempdb损坏 ...
- Linux内存管理(text、rodata、data、bss、stack&heap)
一.各内存区段的介绍 系统内的程序分为程序段和数据段,具体又可细分为一下几个部分: (1)text段-代码段 text段存放程序代码,运行前就已经确定(编译时确定),通常为只读,可以直接在ROM或Fl ...