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 ...
随机推荐
- (转) SQL 命令
省的自己总结了 1.终端启动MySQL:/etc/init.d/mysql start:(stop ,restart.)2.登录MySQL:mysql -uroot -p (用root账户登录),然后 ...
- 如何配置仿真器DM8127+SEED-XDS560v2PLUS和连接不上的问题的解决
1 根据配置焊接JTAG电路转接板.我用的是14pin的. 2 安装仿真器驱动.安装完如下图 我安装的时候没有自动装上,第一次显示问号,后来手动的. 3 设置ccs工程 4 最后调试是这个样子 5 查 ...
- win8 VS控件信息
<TextBlock x:Name="button_1" HorizontalAlignment="Center" TextWrapping=" ...
- git 操作大全
Git 以下内容整理自廖雪峰的git教程,主要用于个人方便使用git命令 git忽略已经被纳入版本库的文件 使用 git update-index –-skip-worktree [file] 可以实 ...
- python中函数总结之装饰器闭包
1.前言 函数也是一个对象,从而可以增加属性,使用句点来表示属性. 如果内部函数的定义包含了在外部函数中定义的对象的引用(外部对象可以是在外部函数之外),那么内部函数被称之为闭包. 2.装饰器 装饰器 ...
- oracle 数据库远程导出
exp 用户名/密码@IP:端口/数据库名 file=文件路径 full=y; exp scebm1/ebm@10.3.10.16:1521/scebm file=D:scebm20140527.dm ...
- ASP.NET下跨应用共享Session和使用Redis进行Session托管简介
在之前的博客中,我说到了Session的共享问题,其中说到了Web Farm和Web Garden两种情况下Session的处理.在ASP.NET提供的Session处理方法中,有以下四种模式: 1. ...
- PHP 碎片
1. $_SERVER['REMOTE_ADDR'] cannot be modified by the user or via HTTP so you CAN trust it. -- 用这个可以有 ...
- 【原创译文】基于Docker和Rancher的超融合容器云架构
基于Docker和Rancher的超融合容器云架构 ---来自Rancher和Redapt 超融合架构在现代数据中心是一项巨大的变革.Nutanix公司发明了超融合架构理论,自从我听说他们的“iPho ...
- datagrid url json
<div class="easyui-accordion" style="width:500px;height:300px;"> <div t ...