当前位置: 首页 > 工具软件 > Hunt Shiro > 使用案例 >

979B - Treasure Hunt

左丘耀
2023-12-01
B. Treasure Hunt
time limit per test
1 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 (0n1090≤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
Copy
3
Kuroo
Shiro
Katie
output
Copy
Kuro
input
Copy
7
treasurehunt
threefriends
hiCodeforces
output
Copy
Shiro
input
Copy
1
abcabc
cbabac
ababca
output
Copy
Katie
input
Copy
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
output
Copy
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 azzzzzzzzand then into zzzzzzzzz thrice. Therefore, the game ends in a draw.


题意:昨晚做的时候,这题读的不是很清晰,感觉有点懵,三个人寻宝,到达了目的地,但是不知道宝藏应该属于谁,就给了三个彩段的字符串,区分大小写,表示不同的颜色,最美的彩段就是子序列(字母)出现最多的,宝藏归最美彩段的人所有,这句. 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. 理解出来的和样例给出的感觉天差地别,翻译出来的就更不能看了,通过有那么一些英语基础,可以知道必须改变n次颜色,每次改变的颜色不同于未改变的颜色。当时这句话,对着样例去看,顿时感觉没读题,懵了...
题解:贪心   看别人代码后,我觉得题意,描述的还是有些问题的。扫面每个字符串,把每个字符串找出里面单独字母出现最多的个数。然后判断
改变次数n如果为1次,并且当前字符串全是一样的,改变一次后,最大的长度为n-1。其余就是max+n和len取最小值。因为如果n的次数大于字符的长度后,肯定输出draw,就不需要必须去算当前每个字符串的具体长度,那样又要考虑很多,脑壳痛....就把它赋值为len。当然也适合那种小于len的。一石二鸟。
#include<bits/stdc++.h>
using  namespace std;
map<char,int>x,y,z;
int n,max1,max2,max3,len;
int main()
{
    string a,b,c;
    cin>>n;
    cin>>a>>b>>c;
    len=a.size();
    for(int i=0; i<len; i++)
    {
        x[a[i]]++,max1=max(x[a[i]],max1);   ///记录每个字符出现最大次数
        y[b[i]]++,max2=max(y[b[i]],max2);
        z[c[i]]++,max3=max(z[c[i]],max3);
    }
    if(n==1&&max1==len) max1--; ///特判n==1和max==len的特殊情况
    else max1=min(max1+n,len);
    if(n==1&&max2==len) max2--;
    else max2=min(max2+n,len);
    if(n==1&&max3==len) max3--;
    else max3=min(max3+n,len);

    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");
    return 0;
}


 类似资料:

相关阅读

相关文章

相关问答