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?
The first line contains an integer nn (0≤n≤1090≤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.
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
3 Kuroo Shiro Katie
Kuro
7 treasurehunt threefriends hiCodeforces
Shiro
1 abcabc cbabac ababca
Katie
15 foPaErcvJ mZaxowpbt mkuOlaHRE
Draw
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次对任一字符。
问:谁能弄出最长的相同的字母的字串。
题解
分两个情况,
1、如果最多字母 T=len 且 n==1 那么,T--;
2、如果最多的字母 T+n>len 那么T=len;
贴上代码
#include<bits/stdc++.h>
using namespace std;
const char ans[][100]={" ","Kuro","Shiro","Katie"};
int main()
{
int n;
while(~scanf("%d",&n)){
char s[3][100005];
for(int i=0;i<3;i++){
scanf("%s",s[i]);
}
int len=strlen(s[0]);
int a[3]={0};
int vis[100]={0};
for(int i=0;i<3;i++){
memset(vis,0,sizeof(vis));
for(int j=0;j<len;j++){
if(islower(s[i][j])){
vis[s[i][j]-'a'+26]++;
a[i]=max(vis[s[i][j]-'a'+26],a[i]);
}else{
vis[s[i][j]-'A']++;
a[i]=max(vis[s[i][j]-'A'],a[i]);
}
}
}
for(int i=0;i<3;i++){
if(a[i]==len&&n==1){
a[i]--;
}else{
a[i]=(a[i]+n>len?len:a[i]+n);
}
}
map<int,int>t;
for(int i=0;i<3;i++){
t[a[i]]=i+1;
}
int b[3]={0};
memcpy(b,a,sizeof(b));
sort(b,b+3);
if(b[2]==b[1]){
printf("Draw\n");
}else {
int tmp=t[b[2]];
printf("%s\n",ans[tmp]);
}
/*for(int i=0;i<3;i++){
printf("%d%c",a[i],i==2?'\n':' ');
}*/
}
return 0;
}