Treasure Hunt CodeForces - 979B
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 77times, 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 nnturns 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 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 105105 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".
Examples
3
Kuroo
Shiro
Katie
Kuro
7
treasurehunt
threefriends
hiCodeforces
Shiro
1
abcabc
cbabac
ababca
Katie
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
Draw
Note
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.
原题链接:http://codeforces.com/problemset/problem/979/B
题目大意:
贪心。
三个人玩游戏,有三个等长字符串,每个人每次可以更改自己字符串中的一个字母,给出可修改次数n,求问最后哪个人的字符串里,重复最多的子串最多,如果有并列第一第二(第三)的情况就平局。
一个串重复次数=这个串里每个字母的重复次数,所以最优是选单个字母重复最多(贪心)。
首先统计串中出现次数最多的字母计数num:
1️⃣若num+n大于字符串长度len,则beauty=len;
2️⃣若num+n小于等于len,则beauty=num+n;
3️⃣特殊情况,若val==len,“aaaaaaaa”,且n==1,最后必然会有一个a变成别的字母,“baaaaaaa”。
即若val==len && n==1 beauty=val--。
有一个样例n=3,aaaaa aaaaa aaaab 结果是draw。如果理解就没问题啦。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int inf = 0x3f3f3f3f; int n;
int len;
int max1, max2, max3;
void print()
{
if (max1>max2&&max1>max3)
{
cout << "Kuro" << endl;
}
else if (max2>max1&&max2>max3)
{
cout << "Shiro" << endl;
}
else if (max3>max1&&max3>max2)
{
cout << "Katie" << endl;
}
else
cout << "Draw" << endl;
}
int work()
{
char s[];
int cnt[];
memset(cnt, , sizeof(cnt));
int ans = -;
scanf("%s", s);
int len = strlen(s);
for (int i = ; i<len; i++)
{
cnt[s[i]]++;
ans = max(ans, cnt[s[i]]);
}
if (ans == len&&n == )
return len - ;
else if (len - ans >= n)
return ans + n;
else
return len;
}
int main()
{
scanf("%d", &n);
max1 = work();
max2 = work();
max3 = work();
print();
getchar();
getchar();
}
Treasure Hunt CodeForces - 979B的更多相关文章
- A. Treasure Hunt Codeforces 线性代数
A. Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Treasure Hunt
Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- zoj Treasure Hunt IV
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- ZOJ3629 Treasure Hunt IV(找到规律,按公式)
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- POJ 1066 Treasure Hunt(相交线段&&更改)
Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...
- poj1066 Treasure Hunt【计算几何】
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8192 Accepted: 3376 Des ...
- zoj 3629 Treasure Hunt IV 打表找规律
H - Treasure Hunt IV Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- ZOJ 3626 Treasure Hunt I 树上DP
E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...
随机推荐
- C++实现反射
之前碰到过一个问题,C++中如何通过一个字符串生成一个类. C++是不支持通过类名称字符串”ClassXX”来生成对象的,也就是说我们可以使用 new ClassXX 来生成对象,但是不能通过 new ...
- linux文本编辑vim命令
1.Vim Vim 是一个功能强大的全屏幕文本编辑器,是 Linux/UNIX 上最常用的文本编辑器,它的作用是建立.编辑.显示文本文件. Vim 没有菜单,只有命令 2.Vim 工作模式 3.插入 ...
- H3C模拟器单臂路由配置实例
单臂路由:用802.1Q和子接口实现VLAN间路由 单臂路由利用trunk链路允许多个VLAN的数据帧通过而实现 网络拓扑图: RTA配置: SW1配置: PC1/2配置如图: 但是值得注意的是,在配 ...
- 转载 vue-awesome-swiper - 基于vue实现h5滑动翻页效果
说到h5的翻页,很定第一时间想到的是swiper.但是我当时想到的却是,vue里边怎么用swiper?! 中国有句古话叫:天塌下来有个高的顶着. 在前端圈里,总有前仆后继的仁人志士相继挥洒着热汗(这里 ...
- react-native-gesture-handler报错
安装React Native第三方组件出现Task :react-native-gesture-handler:compileDebugJavaWithJavac FAILED报错,则使用jetifi ...
- Elasticsearch Lucene 数据写入原理 | ES 核心篇
前言 最近 TL 分享了下 <Elasticsearch基础整理>https://www.jianshu.com/p/e8226138485d ,蹭着这个机会.写个小文巩固下,本文主要讲 ...
- python匿名函数的介绍及用途
匿名函数 用lambda能够创建一个匿名函数,这中函数得名于省略了用def声明函数的标准步骤. 语法 lambda [arg1 [,arg2,.....argn]]:expression 如何使用 我 ...
- 数据结构与算法—二叉排序树(java)
前言 前面介绍学习的大多是线性表相关的内容,把指针搞懂后其实也没有什么难度.规则相对是简单的. 再数据结构中树.图才是数据结构标志性产物,(线性表大多都现成api可以使用),因为树的难度相比线性表大一 ...
- ansible之变量
一.常用系统变量 1. loop #表示循环,去读循环体里的变量固定使用{{item}},item是个字典对象item.key=value,例如如下playbook内容: --- - name: ...
- CentOS 7 中配置Firewall规则
1. 防火墙简介 动态防火墙后台程序 firewalld 提供了一个 动态管理的防火墙,用以支持网络 “zones” ,以分配对一个网络及其相关链接和界面一定程度的信任.它具备对 IPv4和 IPv6 ...