B. Treasure Hunt
time limit per test1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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 77 times, 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 nn turns 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
Input
3
Kuroo
Shiro
Katie
Output
Kuro
Input
7
treasurehunt
threefriends
hiCodeforces
Output
Shiro
Input
1
abcabc
cbabac
ababca
Output
Katie
Input
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
Output
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.

题意:给你一个n和三个字符串,表示操作n次(必须操作),每次必须修改一个字符,问最后三个字符串中,重复次数最多的是哪个。

思路:首先我们遍历一遍,求出每个字符串中单个字符出现次数最多的一个(由贪心知一个子字符串出现几次,那么里面的元素也会出现那么多次,要想让它重复次数最多,肯定是一个字符重复次数越多越好)。如果len=1的话,那么三者肯定会一样;如果重复的最多次数等于len,那么就判断n,如果n等于1,那么当前字符最大次数为len-1,否则和最大次数不等于len一样为min(len,mx+n)

代码实现如下:

 #include <bits/stdc++.h>
using namespace std; int n;
string s[];
int num[][], mx[]; int main() {
ios::sync_with_stdio(false);
cin.tie();
cin >>n;
int len;
memset(num, , sizeof(num));
for(int i = ; i < ; i++) {
cin >>s[i];
len = s[i].size();
for(int v : s[i]) {
num[i][v]++;
}
mx[i] = *max_element(num[i], num[i] + );
if(mx[i] == len) {
if(n == ) {
mx[i] = len - ;
} else {
mx[i] = min(len, mx[i] + n);
}
}
else {
mx[i] = min(len, mx[i] + n);
}
}
if(len == ) cout <<"Draw" <<endl;
else if(count(mx, mx + , *max_element(mx, mx + )) > ) cout <<"Draw" <<endl;
else {
if(mx[] > max(mx[], mx[])) cout <<"Kuro" <<endl;
else if(mx[] > max(mx[], mx[])) cout <<"Shiro" <<endl;
else cout <<"Katie" <<endl;
}
return ;
}

Codeforces Round #482 (Div. 2) B题的更多相关文章

  1. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  2. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  3. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  4. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  5. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  6. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  7. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  8. Codeforces Round #482 (Div. 2) : Kuro and GCD and XOR and SUM (寻找最大异或值)

    题目链接:http://codeforces.com/contest/979/problem/D 参考大神博客:https://www.cnblogs.com/kickit/p/9046953.htm ...

  9. Codeforces Round #482 (Div. 2) :B - Treasure Hunt

    题目链接:http://codeforces.com/contest/979/problem/B 解题心得: 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必 ...

随机推荐

  1. ALPHA-3

    前言 失心疯病源3 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 16:00~20:18 援助行人模块并确定最终框架,顺便不死心的又找了一波车辆检测的dem ...

  2. iOS-根据两个经纬度计算相距距离

    CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue] long ...

  3. Unity3d学习日记(四)

      跟着Unity的教程做了两天,做成了一个叫作survivalShooter的游戏,感觉还挺有意思的,做好后我就把它挂到了个人网站上.   如果你在我的网站的主页的话,点击这个图片就能跳到游戏界面. ...

  4. C# 饼形图

    原文链接:https://www.cnblogs.com/icyJ/archive/2012/10/08/Chart_Pie.html 需要实现的目标是: 1.将数据绑定到pie的后台数据中,自动生成 ...

  5. BZOJ 1452 Count(二维树状数组)

    大水题. 建立100个二维树状数组,总复杂度就是O(qlognlogm). # include <cstdio> # include <cstring> # include & ...

  6. 【bzoj4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+背包dp

    题目描述 给出 $n$ 个括号序列,从中选出任意个并将它们按照任意顺序连接起来,求以这种方式得到匹配括号序列的最大长度. 输入 第一行包含一个正整数n(1<=n<=300),表示括号序列的 ...

  7. PKUWC2019 酱油记

    目录 PKUWC2019 酱油记 day0 Day1 Day2 Day3 Day4 PKUWC2019 酱油记 day0 早上从镇中出发到栎社机场,然后才了解到原来充电宝电脑是必须随身(原以为必须托运 ...

  8. 【以前的空间】link cut tree

    这篇文章讲的很好很详细,但是写了几天后发现似乎是挺残的版本. 2049: [Sdoi2008]Cave 洞穴勘测 3282: Tree 2002: [Hnoi2010]Bounce 弹飞绵羊 1036 ...

  9. [Ahoi2005]COMMON 约数研究 【欧拉线性筛的应用】

    1968: [Ahoi2005]COMMON 约数研究 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 2939  Solved: 2169 [Submi ...

  10. UVALive.3708 Graveyard (思维题)

    UVALive.3708 Graveyard (思维题) 题意分析 这标题真悲伤,墓地. 在周长为1e4的圆周上等距分布着n个雕塑,现在要加入进来m个雕塑,最终还要使得这n+m个雕塑等距,那么原来的n ...