Codeforces Round #482 (Div. 2) B、Treasure Hunt(模拟+贪心)979B
大致题意
n表示要进行n次操作,接着给出三个字符串,表示三个人初始拥有的串。每次操作要替换字符串中的字母,询问最后在游戏中曾出现过的相同的子串谁最多。
思路
(1) 讨论最多的子串,肯定是全部转换成单个的字母是最优的,这样就把子串转换成了讨论出现过最多的字母的问题。接下来只需要模拟,先将初始串中有的最多的字母数统计出来,然后考虑一下剩下的字符数和n的关系就可以了。需要注意的是,初始的字符串是不计入统计的,也就是说,至少在经过一次操作后我们才对它们的最大长度进行比较。
(2)显然只需关注字符而非子串。
枚举每个字符,尽力使其他字符变成它。
只有一种情况需要注意!如果字符a的出现次数等于len,并且n=1,那么你不得不将一个字符a变为其他的字符,最终最多只能有len-1个a.
AC代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<string.h>
using namespace std;
map<char,int>mp;
char s[];
int n;
int so()
{
int ans=-;
mp.clear();
cin>>s;
int len=strlen(s);
for(int i= ; i<len ; i++)
{
mp[s[i]]++;
ans=max(ans,mp[s[i]]);
}
if(ans==len&&n==)
return len-;
else if(ans+n<=len)
return ans+n;
else
return len;
}
int main( )
{
int max1,max2,max3;
scanf("%d",&n);
max1=so(); max2=so();
max3=so();
if(max1>max2&&max1>max3)
puts("Kuro");
else if(max2>max1&&max2>max3)
puts("Shiro");
else if(max3>max1&&max3>max2)
puts("Katie");
else
puts("Draw");
}
Codeforces Round #482 (Div. 2) B、Treasure Hunt(模拟+贪心)979B的更多相关文章
- 【枚举】【贪心】Codeforces Round #482 (Div. 2) B. Treasure Hunt
题意:给你3个字符串,3个人各对自己的字符串执行n轮操作,每一次选择一个字符变为任意一个和原来不同的字符.最后问你谁能使自己的串中的任意重复子串出现的次数最大化. 显然只需关注字符而非子串. 枚举每个 ...
- Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #577 (Div. 2) D. Treasure Hunting
Codeforces Round #577 (Div. 2) D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #482 (Div. 2) B题
题目链接:http://codeforces.com/contest/979/problem/B B. Treasure Hunt time limit per test1 second memory ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #482 (Div. 2) :B - Treasure Hunt
题目链接:http://codeforces.com/contest/979/problem/B 解题心得: 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必 ...
随机推荐
- 【275】◀▶ Python 控制语句说明
参考:Python循环语句 01 for 循环语句. 02 while 循环语句. 03 if...else 选择语句. 04 continue 执行循环语句中的下一条循环. 05 ...
- warning: control reaches end of non-void function 和 warning: implicit declaration of function 'rsgClearColor' is invalid in C99
用gcc编译一个程序的时候出现这样的警告: warning: control reaches end of non-void function 它的意思是:控制到达非void函数的结尾.就是说你的一些 ...
- sort排序应用
private static int SortTestObj2Compare(TestSortClass obj1, TestSortClass obj2) { ...
- 使用ffmpeg合并视频
命令: ffmpeg -i concat:"1.avi|2.avi" -vcodec copy -acodec copy "3.avi" ffmpeg下载:ht ...
- web网页 页面布局的几种方式(转)
web网页 页面布局的几种方式 转载 2017年06月16日 12:19:40 2218 网页基本布局方式: (1)流式布局 Fluid 流布局与固定宽度布局基本不同点 就在于对网站尺寸的侧量单位不同 ...
- SQL查询语句 [2]
一.快捷查询 快捷查询方式是一种多字段查询的简化写法,在多个字段之间用'|'隔开表示OR,用'&'隔开表示 AND. 1.不同字段相同查询条件 在 Home/controller/UserC ...
- GUI编程01
1 tkinter TkInter是标准的Python GUI库.的Python与Tkinter的结合提供了一个快速和容易的方法来创建GUI应用程序. Tkinter的提供了一个强大的面向对象的接口T ...
- 64位系统中fatal error: stdio.h: 没有那个文件或目录的错误的解决方法
Ubuntu系统中可输入如下命令,安装开发环境: sudo apt-get install build-essential https://blog.csdn.net/yygydjkthh/artic ...
- loj10104 [POI 2008]Blockade
传送门 分析 我们知道对于一个割点,我们如果去掉它就会使原来的图被分为若干块,则这是我们将所有块包含的点的个数两两相乘即可,而如果不是割点则对于图的连通性没有影响.注意在最后要加上2*(n-1)表示去 ...
- JavaScript相关知识和经验的碎片化记录
1.JavaScript提示“未结束的字符串常量”错误解决方法 1.1 JavaScript引用时,使用的字符语言不一致. 比如:<script type=”text/javascript ...