题目

大致题意

n表示要进行n次操作,接着给出三个字符串,表示三个人初始拥有的串。每次操作要替换字符串中的字母,询问最后在游戏中曾出现过的相同的子串谁最多。

思路

(1)  讨论最多的子串,肯定是全部转换成单个的字母是最优的,这样就把子串转换成了讨论出现过最多的字母的问题。接下来只需要模拟,先将初始串中有的最多的字母数统计出来,然后考虑一下剩下的字符数和n的关系就可以了。需要注意的是,初始的字符串是不计入统计的,也就是说,至少在经过一次操作后我们才对它们的最大长度进行比较。

(2)显然只需关注字符而非子串。

枚举每个字符,尽力使其他字符变成它。

只有一种情况需要注意!如果字符a的出现次数等于len,并且n=1,那么你不得不将一个字符a变为其他的字符,最终最多只能有len-1个a.

AC代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<string.h>
using namespace std;
map<char,int>mp;
char s[];
int n;
int so()
{
int ans=-;
mp.clear();
cin>>s;
int len=strlen(s);
for(int i= ; i<len ; i++)
{
mp[s[i]]++;
ans=max(ans,mp[s[i]]);
}
if(ans==len&&n==)
return len-;
else if(ans+n<=len)
return ans+n;
else
return len;
}
int main( )
{
int max1,max2,max3;
scanf("%d",&n);
max1=so(); max2=so();
max3=so();
if(max1>max2&&max1>max3)
puts("Kuro");
else if(max2>max1&&max2>max3)
puts("Shiro");
else if(max3>max1&&max3>max2)
puts("Katie");
else
puts("Draw");
}

Codeforces Round #482 (Div. 2) B、Treasure Hunt(模拟+贪心)979B的更多相关文章

  1. 【枚举】【贪心】Codeforces Round #482 (Div. 2) B. Treasure Hunt

    题意:给你3个字符串,3个人各对自己的字符串执行n轮操作,每一次选择一个字符变为任意一个和原来不同的字符.最后问你谁能使自己的串中的任意重复子串出现的次数最大化. 显然只需关注字符而非子串. 枚举每个 ...

  2. Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】

    B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. Codeforces Round #577 (Div. 2) D. Treasure Hunting

    Codeforces Round #577 (Div. 2)  D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...

  4. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  5. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  6. Codeforces Round #482 (Div. 2) B题

    题目链接:http://codeforces.com/contest/979/problem/B B. Treasure Hunt time limit per test1 second memory ...

  7. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Round #482 (Div. 2) :B - Treasure Hunt

    题目链接:http://codeforces.com/contest/979/problem/B 解题心得: 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必 ...

随机推荐

  1. matlab图片高清复制到visio

    编辑→复制图窗→在visio中粘贴

  2. 《Android应用性能优化》 第5章 多线程和同步

    1.DDMS中可以看见的系统线程(Andorid3.1的Galaxy Tab 10.1为例): main HeapWorker 执行finalize函数和引用对象清理 GC Garbage Colle ...

  3. CSS中cursor的pointer 与 hand(转)

    CSS中cursor的pointer 与 hand 转载 2015年12月25日 16:18:36 标签: cursorpointer / cursorhand 1781 cursor:hand 与 ...

  4. Ubuntu重启关机命令使用

    如果你想保持当前用户的登录而且使用root用户执行命令 可以输入:su root,输入密码 可以运行,shutdown 命令 重启命令: 1.reboot 2.shutdown -r now 立刻重启 ...

  5. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-006BitonicMax

    package algorithms.analysis14; import algorithms.util.StdOut; import algorithms.util.StdRandom; /*** ...

  6. 树莓派研究笔记(9)-- 树莓派SPI连接TFT屏幕

    HDMI连接和树莓派专用连接的接口的屏幕都太贵了,为了节约成本,现在国内大多数还是TFT屏幕. 树莓派可以激活SPI接口,通过代码驱动TFT屏幕的显示.这样利用树莓派zero 打造小型的游戏平台可以大 ...

  7. SDUT 3399 数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 冒泡排序和快 ...

  8. java读取classpath下properties文件注意事项

    1.properties文件在classpath根路径下读取方式 Properties properties = new Properties(); properties.load(BlogIndex ...

  9. 免费证书申请——Let's Encrypt的申请与应用(IIS,Tomcat)

    环境 Windows Server 2008 R2 Tomcat 8.5.31 JDK8 利用IIS+letsencrypt-win-simple.V1.9.1申请免费SSL证书 新建一个IIS空网站 ...

  10. Openwrt单独编译某一个模块而不是整个固件

    make package/rt2860v2/compile 就是在make menuconfig那个目录下执行此命令就会编译rt2860v2这个模块