codeforces 979B Treasure Hunt
题意:
给出三个字符串,每个字符串长度相同,给出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的更多相关文章
- Treasure Hunt CodeForces - 979B
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up wit ...
- 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 ...
随机推荐
- Guava cache 示例
pom.xml <!-- guava --> <dependency> <groupId>com.google.guava</groupId> < ...
- SSH的通讯和认证
SSH的通讯和认证 转自:http://blog.sina.com.cn/s/blog_4e9440910100zxk0.html 之前一直对SSH的认证模棱两可,今天对SSH的通讯,认证和配置有了进 ...
- JavaWeb开发如何用Tomcat部署发布
一.如何安装TomCat 1.1安装包下载地址:https://tomcat.apache.org/download-70.cgi 1.2 安装exe文件,下一步直到安装成功.并启动Tomcat服务 ...
- TZOJ 5225: 玩转二叉树
描述 给定一棵二叉树的中序遍历和前序遍历,请你先将树做个镜面反转,再输出反转后的层序遍历的序列.所谓镜面反转,是指将所有非叶结点的左右孩子对换.这里假设键值都是互不相等的正整数. 输入 输入第一行给出 ...
- MVVM软件设计模式(转)
add by zhj: MVVM是一种软件设计模式,这里要说一下设计模式,我们通常所的设计模式是指面向对象中的设计模式,用在面向对象编程语言中.但软件设计模式是更高一个级别的设计模式,两者不是同一个东 ...
- oracle中varchar2(2)存不了一个汉字的原因
错误提示: 一个汉字占了三个字节,而不是两个,这跟字符集有关. 查一下字符集:select userenv('language') from dual; 结果显示,本机Oracle的字符集是UTF-8 ...
- MySQL无损复制(转)
MySQL5.7新特性:lossless replication 无损复制 https://dev.mysql.com/doc/refman/5.7/en/replication-semisync.h ...
- NYOJ 迷宫寻宝(一)
# include<iostream> # include<string> # include<string.h> # include<queue> # ...
- 实例:使用puppeteer headless方式抓取JS网页
puppeteer google chrome团队出品的puppeteer 是依赖nodejs和chromium的自动化测试库,它的最大优点就是可以处理网页中的动态内容,如JavaScript,能够更 ...
- GatewayWorker 分布初试
参考官网分布说明 http://doc2.workerman.net/326144 准备:两台内网服务器A1,A2 A1服务器写PHP脚本前端访问 <?php // 注意这里使用A2服务器的内网 ...