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 ...
随机推荐
- javascript注意点(1)
1.void运算符 ECMAScript 262规范,关于void说明如下: The void Operator The production UnaryExpression : void Unary ...
- bzoj3064 CPU监控
今天终于写了一道正常的题 思路是这样的: 1.普通线段树add,set不变,并改为下放标记版本 2.past_addv 记录一个区间内可能的addv值的最大值 3.past_setv 记录一个区间被s ...
- python测试api接口
在开发中,需要测试web-api的接口 spring mvc 使用单元测试非常方便,但是,受不了单元测试的启动速度.用python写了一个小脚本,用于测试接口, 测试脚本配置文件 api.yaml s ...
- QCon2013上海站总结 -- 前端开发
选择这个专题开始主要有两个原因:一是这次会议关于前端开发的内容不多.二是我做过几年前端开发,这个专题对我来说会容易点:) 这次QCon上海关于前端开发有一个Keynote,一个Javascript专题 ...
- 深入理解HBase Memstore
2013/08/09 转发自http://www.cnblogs.com/shitouer/archive/2013/02/05/configuring-hbase-memstore-what-you ...
- mongdb创建自增主键(primary key)的相关讨论 - Jason.Zhi
根据mongodb官方文档介绍,如果在插入(insert)操作时,没有指定主键id,那么它会自动给插入行自动附上一个主键id.看起来不错,但是详细看看,就会发现这个id值有点复杂. 如下图: mong ...
- SCAU 13校赛 17115 ooxx numbers
17115 ooxx numbers 时间限制:1000MS 内存限制:65535K 题型: 编程题 语言: 无限制 Description a number A called oo numbe ...
- jszs 快速排序
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Android 横屏时禁止输入法全屏
在自己EditText的xml里加上属性 android:imeOptions="flagNoExtractUi"
- LINQ标准查询操作符(一)——select、SelectMany、Where、OrderBy、OrderByDescending、ThenBy、ThenByDescending和Reverse
一.投影操作符 1. Select Select操作符对单个序列或集合中的值进行投影.下面的示例中使用select从序列中返回Employee表的所有列: //查询语法 var query = fro ...