Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/551/problem/B
Description
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x is a string formed by consecutive segment of characters from x. Two substrings of string x overlap if there is position i in string x occupied by both of them.
GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?
Input
All three strings consist only of lowercase English letters.
It is possible that b and c coincide.
Output
Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.
Sample Input
aaa
a
b
Sample Output
aaa
HINT
题意
给你a,b,c三个串,让你随意交换a串的位置,让b串和c串在a串里面不重复的出现最多次
题解:
B题,就老老实实想暴力就好,直接暴力枚举b串出现的次数,然后再算出c串出现的最多次数,然后搞一搞就好了
蛤蛤
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int num[];
int tmp[];
int num11[];
int num22[];
int main()
{
//test;
string a,b,c;
cin>>a>>b>>c;
for(int i=;i<a.size();i++)
num[a[i]-'a']++;
for(int i=;i<b.size();i++)
num11[b[i]-'a']++;
for(int i=;i<c.size();i++)
num22[c[i]-'a']++;
int flag=;
int ans1=,ans2=,ans3=;
int anss=;
for(int i=;i<=a.size();i++)
{
int flag=;
for(int j=;j<;j++)
tmp[j]=num[j];
for(int j=;j<;j++)
{
if(num11[j]*i>tmp[j])
flag=;
else
tmp[j]-=num11[j]*i;
}
if(flag==)
anss++;
if(anss==)
break;
int flag2=inf;
for(int j=;j<;j++)
{
if(num22[j]>)
flag2=min(flag2,tmp[j]/num22[j]);
}
if(flag2==inf)
flag2=;
if(flag)
flag2+=i;
if(ans3<flag2)
{
ans1=i;
ans2=flag2-i;
ans3=flag2;
}
}
for(int i=;i<ans1;i++)
cout<<b;
for(int i=;i<ans2;i++)
cout<<c;
for(int i=;i<;i++)
num[i]=num[i]-num11[i]*ans1;
for(int i=;i<;i++)
num[i]=num[i]-num22[i]*ans2;
for(int i=;i<;i++)
{
while(num[i]>)
{
num[i]--;
printf("%c",i+'a');
}
}
}
Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力的更多相关文章
- 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ
题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain ...
- 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest
题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...
- 「日常训练」ZgukistringZ(Codeforces Round #307 Div. 2 B)
题意与分析(CodeForces 551B) 这他妈哪里是日常训练,这是日常弟中弟. 题意是这样的,给出一个字符串A,再给出两个字符串B,C,求A中任意量字符交换后(不限制次数)能够得到的使B,C作为 ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana (分块)
题目地址:http://codeforces.com/contest/551/problem/E 将n平均分成sqrt(n)块,对每一块从小到大排序,并设置一个总体偏移量. 改动操作:l~r区间内,对 ...
- Codeforces Round #369 (Div. 2) A B 暴力 模拟
A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...
随机推荐
- nmon基础
nmon是分析 AIX 和 Linux 性能的免费工具 最简单的安装方式(Ubuntu apt源) sudo apt-get install nmon 在terminal下打开nmon 敲CMD,出现 ...
- 虚幻4以及DX12将允许开发者利用Xbox One的更多性能(转)
GamingBolt 最近采访了 Epic Games 的总经理 Ray Davis,讨论了有关旗下虚幻引擎(Unreal Engine)的议题.在这次的访谈中,Ray 解释了关于使用 DirectX ...
- 坑爹的gltools编译错误解决
搭边手游,看opengl superbible, 书中代码需要一个gltools库.作者自己提供的code google地址里gltools项目是空的,此一坑. 他的网站(www.starstones ...
- 跨平台音乐播放器qmmp(Cross-Platform Audio Player Qmmp)
开源多媒体播放器(Audio-Player),简洁的界面,最看重它的是跨平台的特性. 开源 跨平台(Linux.Windows) 简洁 支持音乐格式(mp3/ogg......) 全局快捷键 播放中打 ...
- CentOS下安装R
R的Windows版本有直接的安装包,直接下载安装很方便,但是对于CentOS6以上,不能直接通过yum 安装R,需要自己编译. 1. 在编译之前,用yum安装各种软件 (1)安装gcc > y ...
- 为什么要Cssreset
1.CssReset是什么?由于html标签在各浏览器的默认样式解析出来的有所不同.例如<ul>标签在IE.firefox.chrome浏览器下默认边距是不一样的.各浏览器的默认样,会给我 ...
- BITED数学建模七日谈之七:临近比赛时的准备工作
经过前面六天的文章分享,相信大家对数学模型的相关准备.学习都有了更新的认识,希望大家能从中有所收获,以便更高效地准备比赛和学习数学模型,本文是数学建模经验谈的最后一天:临近比赛的准备工作,希望在临近比 ...
- 【工作备忘】suricata
因为工作遇到的困难,我向suricata的某个作者发送了邮件. On Wed, Sep 11, 2013 at 8:22 AM, likeyi <929812468@qq.com> wro ...
- python 抽象类、抽象方法的实现
由于python 没有抽象类.接口的概念,所以要实现这种功能得abc.py 这个类库,具体方式如下 from abc import ABCMeta, abstractmethod #抽象类 class ...
- rm 注意
软连接ln -s lnfile file rm -rf lnfile只是删除lnfile ln -s lndir dir rm -rf lndir 删除链接 rm -rf lndir/删除目录下文件