#482(div.2) B. Treasure Hunt

题目地址:http://codeforces.com/contest/979/problem/B

题目:

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 azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.

思路:

其实这道题,我觉得在考阅读理解。首先三个人给出三个字符串,有一个n是改变次数,比如aaab,n=1,没有改变前,最长公共字符长度L是3,改变一次后为aaaa,所以L=4. 这样就很好理解了。当n=3时,给出aaaa,则,第一次aaab,第二次aaac,第三次aaaa,也就是说只要在n的范围内L可以等于字符串长度,那么L就能取到字符串长度,除非当aaaa的情况下,n=1,那么只能变成aaab,L=3.

先求最多出现的字母个数记为L,如果L+a.length()>a.length()则L=a.length().除非n=1并且L=a.length()时,L=a.length()-1.其余情况L=L+n。然后比较L1,L2,L3得出答案。

代码:

By ZhouShiyue, contest: Codeforces Round #482 (Div. 2), problem: (B) Treasure Hunt, Accepted, #
 #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long int max(long long int a,long long int b,long long int c)
{
    if(a>b&&a>c)return a;
    else if(b>a&&b>c)return b;
    else if(c>a&&c>b)return c;
    else return -1;
}
bool cmp(long long int a,long long int b)
{
    return a>b;
}
long long int tj(string a)
{
    long long int i;
    long long int zm[123];
    memset(zm+0,0,sizeof(zm));
    for(i=0;i<a.length();i++)
    {
        zm[a[i]]++;
    }
    sort(zm,zm+123,cmp);
    return zm[0];
}
int main()
{
    long long int n;
    while(cin>>n)
    {
        string a,b,c;
        long long int l1,l2,l3;
        cin>>a>>b>>c;
        l1=tj(a);l2=tj(b);l3=tj(c);
        if(n==1&&l1==a.length())l1=l1-1;
        else{if(l1+n>a.length())l1=a.length();
        else l1=l1+n;}
         if(n==1&&l2==b.length())l2=l2-1;
         else{
        if(l2+n>b.length())l2=b.length();
        else l2=l2+n;}
          if(n==1&&l3==c.length())l3=l3-1;
          else{
        if(l3+n>c.length())l3=c.length();
        else l3=l3+n;}
        if(l1==max(l1,l2,l3))cout<<"Kuro"<<endl;
        else if(l2==max(l1,l2,l3))cout<<"Shiro"<<endl;
        else if(l3==max(l1,l2,l3))cout<<"Katie"<<endl;
        else cout<<"Draw"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zero_979/article/details/80329805
今日推荐