1. 程式人生 > >Codeforces Round #482 (Div. 2) B題

Codeforces Round #482 (Div. 2) B題

BE 題意 www. finally tdi code fir eterm htm

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 (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
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)

代碼實現如下:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n;
 5 string s[3];
 6 int num[3][128], mx[3];
 7 
 8 int main() {
 9     ios::sync_with_stdio(false);
10     cin.tie(0);
11     cin >>n;
12     int len;
13     memset(num, 0, sizeof(num));
14     for(int i = 0; i < 3; i++) {
15         cin >>s[i];
16         len = s[i].size();
17         for(int v : s[i]) {
18             num[i][v]++;
19         }
20         mx[i] = *max_element(num[i], num[i] + 128);
21         if(mx[i] == len) {
22             if(n == 1) {
23                 mx[i] = len - 1;
24             } else {
25                 mx[i] = min(len, mx[i] + n);
26             }
27         }
28         else {
29             mx[i] = min(len, mx[i] + n);
30         }
31     }
32     if(len == 1) cout <<"Draw" <<endl;
33     else if(count(mx, mx + 3, *max_element(mx, mx + 3)) > 1) cout <<"Draw" <<endl;
34     else {
35         if(mx[0] > max(mx[1], mx[2])) cout <<"Kuro" <<endl;
36         else if(mx[1] > max(mx[0], mx[2])) cout <<"Shiro" <<endl;
37         else cout <<"Katie" <<endl;
38     }
39     return 0;
40 }

Codeforces Round #482 (Div. 2) B題