ujn20161222的博客

life is like a box of chocolates you never know what you re gonna get

B. Treasure Hunt+思维
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 7

because its subribbon a appears 7 times, and the ribbon abcdabc has the beauty of 2

because its subribbon abc appears twice.

The rules are simple. The game will have n

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 n

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 n

(0n109

) — 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 105

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 3

turns, Kuro can change his ribbon into ooooo, which has the beauty of 5, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most 4

, 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 9

and the number of turn is 15, everyone can change their ribbons in some way to reach the maximal beauty of 9 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.

#define happy

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define pll pair<ll,ll>
#define vi vector<int>
#define pb push_back
ll rd(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int cnt[52];
int ch(char c){
    if(c>='a'&&c<='z')return c-'a';
    return c-'A'+26;
}
const int N=1e5+10;
char u[N];
int getans(int n){
    scanf("%s",u);
    int i,len=strlen(u);
    memset(cnt,0,sizeof(cnt));
    rep(i,0,len-1)cnt[ch(u[i])]++;
    if(len==1)return 1;
    int mx=0;
    rep(i,0,51)mx=max(mx,cnt[i]);
    if(mx==len){
        if(n==1)return mx-1;
        return mx;
    }
    return min(len,mx+n);
}


int main(){
#ifdef happy
    freopen("in.txt","r",stdin);
#endif
    int n=rd();
    int v[3];
    v[0]=getans(n);
    v[1]=getans(n);
    v[2]=getans(n);
    int mx=max(v[0],max(v[2],v[1]));
    int c=0;
    rep(i,0,2)if(v[i]==mx)c++;
    if(c>=2)return puts("Draw"),0;
    if(v[0]==mx)puts("Kuro");
    if(v[1]==mx)puts("Shiro");
    if(v[2]==mx)puts("Katie");
    return 0;
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ujn20161222/article/details/80320930
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

B. Treasure Hunt+思维

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭