B. Treasure Hunt

B. Treasure Hunt
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
(
0

n

10
9
) — 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
10
5
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
inputCopy
3
Kuroo
Shiro
Katie
outputCopy
Kuro
inputCopy
7
treasurehunt
threefriends
hiCodeforces
outputCopy
Shiro
inputCopy
1
abcabc
cbabac
ababca
outputCopy
Katie
inputCopy
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
outputCopy
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.

#include <stdio.h>
#include <stdlib.h>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
char str[100001];
int vas[5];
int main()
{
    long long int n,len,i,j,t;
    memset(vas,0,sizeof(vas));
    map<char,int>s;
    scanf("%lld",&n);
    for(i=1; i<=3; i++)
    {
        scanf("%s",str);
        len=strlen(str);
        for(j=0; j<len; j++)
        {
            s[str[j]]++;
            vas[i]=max(vas[i],s[str[j]]);//后面如果出现相等的字母,那对应的键值是一样的,就会加加
        }
        if(n==1&&vas[i]==len)
            vas[i]=len-1;//如果有一次操作,但这时候已经满足最大值了,
            //这时候就会改变一个数,使他变成不一样的,那就会在原先基础上减一
        else vas[i]=min(vas[i]+n,len);//进行n次循环,肯定会改成和出现次数最大的字母一样的字母n次
        //当已经是len时候和超过len的时候都是len
        s.clear();//用完要清空
    }
    int maxx=0;
    for(i=1; i<=3; i++)
    {
        if(vas[i]>maxx)
        {
            maxx=vas[i];
            t=i;
        }
    }//先找到出现次数最多的字母的个数;
    for(i=1;i<=3;i++)
    {
        if(t!=i&&vas[t]==vas[i])
        {
            printf("Draw\n");
            return 0;
        }
    }//进行是否相等的判断
    if(t==1)
    {
        printf("Kuro\n");
    }
    else if(t==2)
    {
        printf("Shiro\n");
    }
    else printf("Katie\n");
    return 0;
}

题意:给我们一串数字找最大的连续子串,n次循环可以改动N 次 ,具体解释在代码里

猜你喜欢

转载自blog.csdn.net/bhliuhan/article/details/80551490
今日推荐