Codeforces Round #585 (Div. 2) D. Ticket Game
链接:
https://codeforces.com/contest/1215/problem/D
题意:
Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.
Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n2 digits of this ticket is equal to the sum of the last n2 digits.
Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket.
If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.
思路:
考虑两半, 如果和相等, 则?树也要相等.
如果l>r, 则l的问号要小于r,同时两边的问号差为sub, 考虑为了补充右边等于左边, 如果左边较小则填较大使其不成立, 较大则填较小.所有只有差值为sub/2*9时成立.
这样两人一起的贡献和为9.正好填充相等.
代码:
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int main()
{
cin >> n;
cin >> s;
int sum1 = 0, sum2 = 0, num1 = 0, num2 = 0;
for (int i = 0;i < n;i++)
{
if (i < n/2)
{
if (s[i] == '?')
num1++;
else
sum1 += s[i]-'0';
}
else
{
if (s[i] == '?')
num2++;
else
sum2 += s[i]-'0';
}
}
if (sum1 < sum2)
swap(sum1, sum2), swap(num1,num2);
if (sum1 == sum2)
{
if (num1 == num2)
puts("Bicarp");
else
puts("Monocarp");
return 0;
}
if (num1 > num2)
{
puts("Monocarp");
return 0;
}
int need = sum1-sum2;
int own = ((num2-num1)/2)*9;
if (need != own)
puts("Monocarp");
else
puts("Bicarp");
return 0;
}
Codeforces Round #585 (Div. 2) D. Ticket Game的更多相关文章
- Codeforces Round #585 (Div. 2)
https://www.cnblogs.com/31415926535x/p/11553164.html 感觉很硬核啊这场,,越往后越做不动,,,emmmm,,,(这场是奔着最后一题 2sat 来的, ...
- Codeforces Round #585 (Div. 2) C. Swap Letters
链接: https://codeforces.com/contest/1215/problem/C 题意: Monocarp has got two strings s and t having eq ...
- Codeforces Round #585 (Div. 2) B. The Number of Products(DP)
链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ...
- Codeforces Round #585 (Div. 2) A. Yellow Cards(数学)
链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup ha ...
- Codeforces Round #585 (Div. 2) [补题]
前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
- Codeforces Round #585 (Div. 2) E. Marbles (状压DP)
题目:https://codeforc.es/contest/1215/problem/E 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
- Codeforces Round #585 (Div. 2)E(状态压缩DP,思维)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h>using namespace std;long long n,x;long lon ...
随机推荐
- SQL入门经典(第四版)学习记录——欢迎来到SQL世界(一)
1.结构化查询语言——SQL,关系型数据库通信的标准语言: 2.关系型数据库:表的逻辑单元组成,这些表在内部彼此关联,组成了关系型数据库: 3.SQL会话:用户用SQL命令语句与关系型数据库进行交互时 ...
- 【坑】springMvc 信息校验,读取不到错误配置信息的问题
文章目录 前言 ResourceBundleMessageSource 后记 前言 springMvc 的一大利器,validation 检验,通过注解,可以帮我们完成校验,很是顺手. 终极偷懒检验, ...
- Win10 彻底关闭 Windows Defender
1.使用快捷键 WIN+R 调出运行工具,然后再输入组策略命令 gpedit.msc 再点击确定. 2.进入组策略在计算机配置下面的管理模板,Windows 组件就可以看到 Windows Defen ...
- MySQL忘记密码解决
1.设置管理员root密码为123 开启MySQL服务后 PS C:\WINDOWS\system32> mysqladmin -uroot -p password "123" ...
- 给内部类对象数组属性赋值时报错:Exception in thread "main" java.lang.NullPointerException
前言 1255: 打怪升级(Java),写这个题目程序的时候,控制台提示如下错误: Exception in thread "main" java.lang.NullPointer ...
- zcat +文件名.gz | grep "查找内容"
linux gz查看 zcat +文件名.gz | grep "查找内容" 解压 rar x xxxx.rar
- 基于搜索的贝叶斯网络结构学习算法-K2
基于搜索的贝叶斯网络结构学习算法-K2 2018-04-05 19:34:18 ItsBlue 阅读数 3172更多 分类专栏: 贝叶斯网络 网络结构学习 版权声明:本文为博主原创文章,遵循CC ...
- Prometheus Grafana监控全方位实践
这次就不用 docker 部署服务了,这样大家会更容易接受.欢迎阅读. 引言 Prometheus 是一个监控系统,也是一个时间序列数据库,用Go语言开发的,官方文档.通过从某些特定的目标如主机,My ...
- Https的作用
在普通的网络环境下,HTTP请求存在DNS劫持.运营商插入广告.数据被窃取,正常数据被修改等安全风险.使用HTTPS协议可以保证数据传输的安全性. Https的作用: 内容加密 建立一个信息安全 ...
- JS基础_函数作用域
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...