题意:

给出三个字符串,每个字符串长度相同,给出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. vue打包后出现"Failed to load resource: net::ERR_FILE_NOT_FOUND"错误

    创建vue脚手架搭建项目之后,用npm run build经行打包,运行index.html后出现异常: 打开dist/index.html, 诸如这些的,引入是有问题的, 这边的全部是绝对路径,而本 ...

  2. vue安装调试器Vue.js devtools

    一. 打开https://github.com/vuejs/vue-devtools,进入gitlab.往下翻找到: 找到installation,选择以chrome的拓展方式安装. 二. 这边选择添 ...

  3. 命令行颜色换算器(基于python)

    import sys print(hex(int(sys.argv[1])<<16|int(sys.argv[2])<<8|int(sys.argv[3]))) 就两行代码 在 ...

  4. IntelliJ常用设置及快捷键

    转自: http://www.blogjava.net/rockblue1988/archive/2014/10/25/418994.html 一.黑色主题 Darcula眼睛舒服,最重要的是酷!设置 ...

  5. Interceptor的基本介绍和使用

    简介 java里的拦截器是动态拦截Action调用的对象,它提供了一种机制可以使开发者在一个Action执行的前后执行一段代码,也可以在一个Action执行前阻止其执行,同时也提供了一种可以提取Act ...

  6. jvm的调优

    首先我们要知道jvm的调优,主要是对那些部分的优化.通过jvm内存模型我们可以,首先是分析遇到的问题,然后通过一些工具或者手段找到问题所在,然后通过一定的措施解决问题,下面我们也将按着这个思路来给出具 ...

  7. shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出

    shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出 如: #/bin/sh local ret='sqlite3 test.db "select test ...

  8. javax.lang.model Implementation Backed by Core Reflection

    javax.lang.model Implementation Backed by Core Reflection 1.javax.lang.model: How do I get the type ...

  9. 帝国cms调用相关文章若没有则调取最新文章

    前面我们说了帝国cms调用最新文章 利用文字调用标签phomenews,现在我们说下相关文章的调用,如果文章有设置关键词的话可以直接用[!--other.link--]进行调取,现在我们来升级一下,如 ...

  10. 各版本系统安装tesseract-ocr

    Mac版本 1.tesseract-ocr安装  brew install tesseract-ocr 注意:如果未安装brew命令,可以输入命令: brew官网:http://brew.sh /us ...