Treasure Hunt CodeForces - 979B
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of 77 because its subribbon a appears 77times, and the ribbon abcdabc has the beauty of 22 because its subribbon abc appears twice.
The rules are simple. The game will have nn turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after nnturns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
Input
The first line contains an integer nn (0≤n≤1090≤n≤109) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than 105105 uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
Output
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
Examples
3
Kuroo
Shiro
Katie
Kuro
7
treasurehunt
threefriends
hiCodeforces
Shiro
1
abcabc
cbabac
ababca
Katie
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
Draw
Note
In the first example, after 33 turns, Kuro can change his ribbon into ooooo, which has the beauty of 55, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most 44, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is 99 and the number of turn is 1515, everyone can change their ribbons in some way to reach the maximal beauty of 99 by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
原题链接:http://codeforces.com/problemset/problem/979/B
题目大意:
贪心。
三个人玩游戏,有三个等长字符串,每个人每次可以更改自己字符串中的一个字母,给出可修改次数n,求问最后哪个人的字符串里,重复最多的子串最多,如果有并列第一第二(第三)的情况就平局。
一个串重复次数=这个串里每个字母的重复次数,所以最优是选单个字母重复最多(贪心)。
首先统计串中出现次数最多的字母计数num:
1️⃣若num+n大于字符串长度len,则beauty=len;
2️⃣若num+n小于等于len,则beauty=num+n;
3️⃣特殊情况,若val==len,“aaaaaaaa”,且n==1,最后必然会有一个a变成别的字母,“baaaaaaa”。
即若val==len && n==1 beauty=val--。
有一个样例n=3,aaaaa aaaaa aaaab 结果是draw。如果理解就没问题啦。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int inf = 0x3f3f3f3f; int n;
int len;
int max1, max2, max3;
void print()
{
if (max1>max2&&max1>max3)
{
cout << "Kuro" << endl;
}
else if (max2>max1&&max2>max3)
{
cout << "Shiro" << endl;
}
else if (max3>max1&&max3>max2)
{
cout << "Katie" << endl;
}
else
cout << "Draw" << endl;
}
int work()
{
char s[];
int cnt[];
memset(cnt, , sizeof(cnt));
int ans = -;
scanf("%s", s);
int len = strlen(s);
for (int i = ; i<len; i++)
{
cnt[s[i]]++;
ans = max(ans, cnt[s[i]]);
}
if (ans == len&&n == )
return len - ;
else if (len - ans >= n)
return ans + n;
else
return len;
}
int main()
{
scanf("%d", &n);
max1 = work();
max2 = work();
max3 = work();
print();
getchar();
getchar();
}
Treasure Hunt CodeForces - 979B的更多相关文章
- A. Treasure Hunt Codeforces 线性代数
A. Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Treasure Hunt
Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- zoj Treasure Hunt IV
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- ZOJ3629 Treasure Hunt IV(找到规律,按公式)
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- POJ 1066 Treasure Hunt(相交线段&&更改)
Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...
- poj1066 Treasure Hunt【计算几何】
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8192 Accepted: 3376 Des ...
- zoj 3629 Treasure Hunt IV 打表找规律
H - Treasure Hunt IV Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- ZOJ 3626 Treasure Hunt I 树上DP
E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...
随机推荐
- Java编程思想之十七 容器深入研究
17.1 完整的容器分类方法 17.2 填充容器 import java.util.*; class StringAddress { private String s; public StringAd ...
- Maven项目的打包发布到Nexus私服和服务器
1.编写pom文件如下: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins< ...
- KD-tree 专题「Hide and Seek · 巧克力王国」
Lockey的瞎理解 抄了一遍板子又水了俩题,感觉对KD-tree 稍稍理解了一点儿,唠叨一下(二维的KD-tree),如有错误请指出(Lockey 洗脸恭听) 普通平衡树维护的是一维的序列,但对于二 ...
- ansible批量管理服务 下
1 ansible-playbook 任务剧本 1.1 剧本文件概念 (1)playbook可以将多个批量操作模块功能整合,完成一件事情.(2)简化运维工作复杂度(3)playbook通过yaml语法 ...
- python 列表的增删改查
列表 有序可变的,索引 作用:存储数据的,支持很多种数据类型 定义方式: lst = [1,"alex",True,('a','b')]增 append() # 追加 extend ...
- Mybatis学习笔记之---多表查询(1)
Mybatis多表查询(1) (一)举例(用户和账户) 一个用户可以有多个账户 一个账户只能属于一个用户(多个账户也可以属于同一个用户) (二)步骤 1.建立两张表:用户表,账户表,让用户表和账户表之 ...
- flask项目部署到云服务器+域名绑定
一.效果演示 首页展示 播放页面 该项目部署只为学习,所以用的服务器是腾讯云服务器10元/月,域名也是在腾讯云买的.com 55元/年 因为本人比较穷 哈哈
- Mac如何前往文件夹 修改hosts文件 显示隐藏文件 Mac如何查看剪切板
Mac 如何前往文件夹 首先,回到桌面,或者点击Finder(访达) 然后输入快捷键 ⌘ Command + ⇧ Shift + G 或者在Finder上方状态栏中点击‘前往’>>> ...
- c# NPOI 导出23万条记录耗时12秒
先上测试代码: string connectionString = "Server=localhost;Initial Catalog=******;User ID=sa;Password= ...
- JS实现循环删除数组中元素的方法介绍
这篇文章主要给大家介绍了关于Javascript循环删除数组中元素的几种方法,文中给出了详细的示例代码供大家参考学习,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧. 本文主要跟大家分享了 ...