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轮游戏,每一轮三个人必 ...
随机推荐
- spring整合mybatis的事物管理配置
一.基本配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...
- js在浏览器下的区别小结(部分)
1.初始化数组: document.write([1,2,3,].length); IE:4//把数组中最后一个逗号后面的当做了undefined元素 FF.Opera.Safari:3 2.join ...
- C++面向对象类的实例题目七
题目描述: 编写两个有意义的类,使一个类嵌套在另一个类中. 分析: 本题涉及两个类student和cdegree,前者为学生类,包含学生的学号(nubner),姓名(name)和成绩(degree), ...
- MSScriptControl详解(可实现在C#等语言中调用JAVASCRIPT代码)
ScriptControl接口 属性名称 类型 备注 AllowUI BOOL 检测是否允许运行用户的接口元素.如果为False,则诸如消息框之类的界面元素不可见. CodeObject Object ...
- Linux共享对象之编译参数 -fPIC
转载自:https://www.cnblogs.com/cswuyg/p/3830703.html 在Linux系统中,动态链接文件称为动态共享对象(DSO,Dynamic Shared Ob ...
- cakephp数据库配置
- Entity Framework Tutorial Basics(14):Choose development approach
Choose development approach with Entity Framework: We have seen Code-first, Model-first and Database ...
- js/jq基础(日常整理记录)-4-一个简单的自定义tree插件
一.一个简单的自定义tree插件 上一篇是之前自定义的table插件,这一篇也是之前同期尝试做的一个tree插件. 话不多说,先看看长什么样子哈! 现在来看确实不好看,以后在优化吧! 数据源:ajax ...
- Linux sogou input method
afda@afda-Y720-15IKB:~$ wget "http://pinyin.sogou.com/linux/download.php?f=linux&bit=64&quo ...
- iOS应用推荐
RSS阅读器 Inoreader ***客户端 SuperWingy OpenWingy(已下架) 书签 Pocket 语音备忘录 Voice-Memos 编程语言学习 SoloLearn 社交 Tw ...