题意:

给出三个字符串,每个字符串长度相同,给出n,要求在n轮内,每一个字符串必须改变一个字符。

问最后哪个字符串中拥有最多相同的字符,即美丽度最大。

思路:

首先,很不容易想到的一点是从a变到a,有两种方式a -> 其它 -> a,或者a -> 其它 -> 其它 -> a,即变2次或者变3次。

变3次是有意义的,比如第86个样例(wa在第86):

3

aaaaa

aaaaa

aaaab

答案是draw

因为第一个选一个a变3次变回a,第二个同理,第三个b到a再到b再到a就可以了,所以可以相同,这里存在一个误区。

根据这一组数据发现,唯一可能变少的情况就是这个字符串全部字母相同并且n = 1,那么最后的美丽度要减一,比如aaaaa,只能变一个,所以美丽度减一。

其它情况按照普通情况处理就好了。

相加大于len的直接取为len就ok。

代码:

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
const int N = 1e5 + ;
char a[N],b[N],c[N];
map<char,long long> as,bs,cs;
int main()
{
long long n;
scanf("%lld",&n);
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
int len = strlen(a);
for (int i = ;i < len;i++)
{
as[a[i]]++;
}
for (int i = ;i < len;i++)
{
bs[b[i]]++;
}
for (int i = ;i < len;i++)
{
cs[c[i]]++;
}
long long aa = ,bb = ,cc = ;
if (as.size() == && n == )
{
aa = len - ;
}
else
{
for (auto it = as.begin();it != as.end();++it)
{
aa = max(aa,it -> second + n);
}
if (aa > len) aa = len;
}
if (bs.size() == && n == )
{
bb = len - ;
}
else
{
for (auto it = bs.begin();it != bs.end();++it)
{
bb = max(bb,it -> second + n);
}
if (bb > len) bb = len;
}
if (cs.size() == && n == )
{
cc = len - ;
}
else
{
for (auto it = cs.begin();it != cs.end();++it)
{
cc = max(cc,it -> second + n);
}
if (cc > len) cc = len;
}
long long ans = max(aa,bb);
ans = max(ans,cc);
int cnt = ;
int ma = -;
if (aa == ans)
{
cnt++;
ma = ;
}
if (bb == ans)
{
cnt++;
ma = ;
}
if (cc == ans)
{
cnt++;
ma = ;
}
//printf("%d*\n",ma);
if (cnt >= ) puts("Draw");
else
{
if (ma == ) puts("Kuro");
if (ma == ) puts("Shiro");
if (ma == ) puts("Katie");
}
return ;
}

codeforces 979B Treasure Hunt的更多相关文章

  1. Treasure Hunt CodeForces - 979B

    After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up wit ...

  2. A. Treasure Hunt Codeforces 线性代数

    A. Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. Treasure Hunt

    Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. zoj Treasure Hunt IV

    Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland ...

  5. POJ 1066 Treasure Hunt(线段相交判断)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4797   Accepted: 1998 Des ...

  6. ZOJ3629 Treasure Hunt IV(找到规律,按公式)

    Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland ...

  7. POJ 1066 Treasure Hunt(相交线段&amp;&amp;更改)

    Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...

  8. poj1066 Treasure Hunt【计算几何】

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8192   Accepted: 3376 Des ...

  9. zoj 3629 Treasure Hunt IV 打表找规律

    H - Treasure Hunt IV Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu ...

随机推荐

  1. # 20165225 《Java程序设计》第一周学习总结

    20165225 <Java程序设计>第一周学习总结 1.视频与课本中的学习: 首先是为了运行和开发Java分别安装了JRE和JDK,具体做法在老师给的<Java2 实用教程(第五版 ...

  2. 基于w2v词向量聚类出现的问题(有待解决)

    1.训练词向量代码如下:#训练词语为向量表示def w2v_train(self): ques = self.cu.execute('select question from activity')#将 ...

  3. [转载]智能科普:VR、AR、MR的区别

    智能科普:VR.AR.MR的区别 http://news.zol.com.cn/553/5534833.html news.zol.com.cn 2015-11-23 16:00 近日, 获得谷歌5亿 ...

  4. Linux dmidecode 命令

    当我们需要获取机器硬件信息时,可使用linux系统自带的dmidecode工具进行查询. dmidecode 用于获取服务器的硬件信息,通常是在不打开计算机机箱的情况下使用该命令来查找硬件详细信息 这 ...

  5. 循环打印视图(学习WHILE循环)

    ) --视图名 --总视图数 --循环次数 SELECT @RowCount = COUNT(NAME) FROM sysobjects WHERE xtype = 'v' WHILE @i < ...

  6. CA证书和TLS介绍

    数字签名 用自己的私钥给数据加密就叫数字签名 公钥传输威胁 在A和B的通信中,C可以把自己的公钥发给A,让A把C的公钥当成B的公钥,这样的话.B拿到加密数据反而无法解密,而C却可以解密出数据.从而实现 ...

  7. wxPython:文本对话框TextEntryDialog

    wxTextEntryDialog(wxWindow* parent, const wxString& message, const wxString& caption = " ...

  8. PHP中MySQL、MySQLi和PDO的用法和区别

    PHP的MySQL扩展(优缺点) 设计开发允许PHP应用与MySQL数据库交互的早期扩展.mysql扩展提供了一个面向过程 的接口: 并且是针对MySQL4.1.3或更早版本设计的.因此,这个扩展虽然 ...

  9. javaScript 数组迭代方法

    map 方法 解释:map即映射,返回对每项操作后组成的新数组 let arr=[1,2,3,4,5,6,7,8]; let newArr=arr.map((item)=>{ if(item&g ...

  10. jquery中把一串字符串分割,如:123456789后者abcdefg类型的

    函数:slice() 功能:arrayObject.slice(start,end) start:必需.规定从何处开始选取.如果是负数,那么它规定从数组尾部开始算起的位置.也就是说,-1 指最后一个元 ...