题目地址:http://codeforces.com/contest/979/problem/B
题目:
思路:
其实这道题,我觉得在考阅读理解。首先三个人给出三个字符串,有一个n是改变次数,比如aaab,n=1,没有改变前,最长公共字符长度L是3,改变一次后为aaaa,所以L=4. 这样就很好理解了。当n=3时,给出aaaa,则,第一次aaab,第二次aaac,第三次aaaa,也就是说只要在n的范围内L可以等于字符串长度,那么L就能取到字符串长度,除非当aaaa的情况下,n=1,那么只能变成aaab,L=3.
先求最多出现的字母个数记为L,如果L+a.length()>a.length()则L=a.length().除非n=1并且L=a.length()时,L=a.length()-1.其余情况L=L+n。然后比较L1,L2,L3得出答案。
代码:
By ZhouShiyue, contest: Codeforces Round #482 (Div. 2), problem: (B) Treasure Hunt, Accepted, #
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long int max(long long int a,long long int b,long long int c)
{
if(a>b&&a>c)return a;
else if(b>a&&b>c)return b;
else if(c>a&&c>b)return c;
else return -1;
}
bool cmp(long long int a,long long int b)
{
return a>b;
}
long long int tj(string a)
{
long long int i;
long long int zm[123];
memset(zm+0,0,sizeof(zm));
for(i=0;i<a.length();i++)
{
zm[a[i]]++;
}
sort(zm,zm+123,cmp);
return zm[0];
}
int main()
{
long long int n;
while(cin>>n)
{
string a,b,c;
long long int l1,l2,l3;
cin>>a>>b>>c;
l1=tj(a);l2=tj(b);l3=tj(c);
if(n==1&&l1==a.length())l1=l1-1;
else{if(l1+n>a.length())l1=a.length();
else l1=l1+n;}
if(n==1&&l2==b.length())l2=l2-1;
else{
if(l2+n>b.length())l2=b.length();
else l2=l2+n;}
if(n==1&&l3==c.length())l3=l3-1;
else{
if(l3+n>c.length())l3=c.length();
else l3=l3+n;}
if(l1==max(l1,l2,l3))cout<<"Kuro"<<endl;
else if(l2==max(l1,l2,l3))cout<<"Shiro"<<endl;
else if(l3==max(l1,l2,l3))cout<<"Katie"<<endl;
else cout<<"Draw"<<endl;
}
return 0;
}