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轮游戏,每一轮三个人必 ...
随机推荐
- php中定义数组的方法
1.PHP定义数组的格式 数组名=array(); 如:$aa=array();//这样就定义了一个数组, 之后给元素赋值: $aa[0]="9016"; $aa[1]=" ...
- CentOS7:ifconfig command not found解决和netstat -an
没有 ifconfig 和netstat -an 的话安装 net-tools package yum install net-tools
- Mysql GROUP_CONCAT 使用注意事项
GROUP_CONCAT 函数返回一个字符串结果,该结果由分组中的值连接组合而成,常和 GROUP BY 连用. 如果需要自定义分隔符可以使用 SEPARATOR. 示例: SELECT GROUP_ ...
- Java-马士兵设计模式学习笔记-策略模式-模拟 Comparator接口
续上一篇 <Java 模拟 Comparable接口> 一.Teacher类及Student类的比较大小方式是不固定的,比如老师除了比较职称外,还可比较工龄大小,年龄大小等.则定义Com ...
- Paxos在大型系统中的应用场景
https://timyang.net/distributed/paxos-scenarios/ 在分布式算法领域,有位非常重要的短发叫Paxos,它的重要性有多高呢?Google的Chubby[1] ...
- JavaScript相关知识和经验的碎片化记录
1.JavaScript提示“未结束的字符串常量”错误解决方法 1.1 JavaScript引用时,使用的字符语言不一致. 比如:<script type=”text/javascript ...
- 如何设置Oracle process值
参考链接:http://blog.51cto.com/sunwayle/88870 su - oracle sqlplus system as sysdba; show parameter proce ...
- C#实现远程开机(局域网测试通过)
首先介绍相关知识. UDP协议 UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联 ...
- C#字符串要点(复习专用)
一.字符串 通过string定义一个字符串,或者通过String类来创建对象. 通过new String() 创建有一下几种构造函数(从元数据),以此顺序创建string: // // 摘要: // ...
- 基于DEV控件库的webservice打印.repx模板
本文使用的DEV版本为10.1版本 首先需要添加Dll引用 DevExpress.Data.v10.1 DevExpress.XtraPrinting.v10.1 DevExpress.XtraRep ...