Codeforces Round #482 (Div. 2) 979B - Treasure Hunt [思维]

在一个名为“寻宝”的游戏中,三只聪明的猫科动物通过改变它们彩色丝带的颜色来竞争获得宝藏的所有权。每轮比赛中,每只猫都必须更改其丝带上的一种颜色。目标是在给定的轮数后拥有最漂亮的丝带。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 105105uppercase 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次操作(将一个字符变为一个与其不同的字符),问最后谁的相同字符数量最大。。。

思路:首先我说一下,比赛时读错题是真的很凉,就是直接找出现次数最多的字符串,然后判断一下就好了,为什么我非要想成连续的呢,真的好凉,求出字符串出现次数最多的,

当nmax == len&&n == 1时,长度是len - 1;

当n <= len - nmax时, 长度是nmax + n;

否则 总有办法达到长度为len;

代码:

 

#include<bits/stdc++.h>
#include<map>
#define ll long long

using namespace std;
const int maxn = 1e5+7;
int n, p[3];
char a[maxn];
map<char, int> mp;
map<char, int> :: iterator it;

int find(char s[])
{
    mp.clear();
    int len = strlen(s), nmax = 0;
    for(int i = 0; i < len; i++) mp[s[i]]++;
    for(it = mp.begin(); it != mp.end(); it++)
    nmax = max(nmax, (it->second));
    if(n == 1&&nmax == len) nmax = len - 1;
    else if(len - nmax >= n) nmax += n;
    else nmax = len;
    return nmax;
}



int main()
{
    //freopen("in.txt", "r", stdin);
    while(~scanf("%d",&n))
    {
        for(int i = 0; i < 3; i++) {
                scanf("%s", a);
                p[i] = find(a);
        }
        int nmax = max(p[0], max(p[1], p[2]));
        if((p[0] == nmax&&p[1] == nmax)||(p[0] == nmax&&p[2] == nmax)||(p[1] == nmax&&p[2] == nmax)) puts("Draw");
        else if(p[0] == nmax) puts("Kuro");
        else if(p[1] == nmax) puts("Shiro");
        else if(p[2] == nmax) puts("Katie");
        else puts("Draw");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值