codeforces979B Treasure Hunt——贪心

题目描述


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".


三个人有三个等长字符串,没人每次可以更改自己字符串中的一个字母,给出可修改次数n,求问最后哪个人的字符串里,重复最多的子串的重复数最多,如果有并列第一第二(第三)的就平局。

一个串重复次数=这个串里每个字母的重复次数,所以最优是选单个字母重复最多。


首先统计串中出现次数最多的字母计数val:

~~若val+n大于字符串长度len,则beauty=len;

~~若val+n小于等于len,则beauty=val+n;

~~特殊情况,若val==len,“aaaaaaaa”,且n==1,最后必然会有一个a变成别的字母,“baaaaaaa”。

      即若val==len && n==1 beauty=val--;


代码如下

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

long long n;
char str[3][100005];
int len;
int book[3][300];
struct mmax{
    int val;
    char *name;
}m[3]={{0,"Kuro"},{0,"Shiro"}, {0,"Katie"}};


bool cmp(mmax a, mmax b){
    return a.val>b.val;
}

int main(){
    cin>>n;
    for(int i=0;i<3;i++){
        cin>>str[i];
    }
    len=strlen(str[0]);

    memset(book,sizeof(book),0);


    for(int i=0;i<3;i++){
        for(int j=0;j<len;j++){
            book[i][str[i][j]]++;
            m[i].val=max(book[i][str[i][j]], m[i].val);
        }
        if(n==1&&m[i].val==len) m[i].val--;
        else if(m[i].val+n<=len) m[i].val+=n;
        else if(m[i].val+n>len) m[i].val=len;
    }



    sort(m,m+3,cmp);
    if(m[0].val==m[1].val){
        cout<<"Draw"<<endl;
    }else{
        cout<<m[0].name<<endl;
    }


    return 0;
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值