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 ...
随机推荐
- java积累的细节问题
一.将几个数字进行拼接,拼接成字符串 一定要将""放到几个数字之前,否则就会把数字相加之后的数转化成字符串 如你需要拼接年份,月份,和日 如果:2018+12+13+"& ...
- Word、Excel、PPT 2016、2013、2010、2007 没有保存或断电导致文件丢失怎么恢复?
1. 前言 没有保存文档还能恢复吗?死机.断电.蓝屏导致来不及保存文档,还能恢复吗?答案当然是可以的!Office中本身就有恢复文档的功能,可以帮助我们最大化的挽回损失. Office2013与Off ...
- LC 206. Reverse Linked List
题目描述 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5-> ...
- Django导出数据为Excel,调用浏览器下载
1. 环境 Django (2.1.10) + Python3.6 + xlwt (1.3.0) 操作系统使用的为:Windows 7 2. 接口代码 def now_export(request): ...
- List 集合 使用 remove 踩得坑
不要在 foreach 循环里进行元素的 remove/add 操作.remove 元素请使用 Iterator方式,如果并发操作,需要对 Iterator 对象加锁. 正确例子: Iterato ...
- R|批量循环处理同一格式文件-csv,txt,excel
本文首发于“生信补给站”微信公众号,https://mp.weixin.qq.com/s/8IfMrSr9xc8_1Y2_9Ne6hg 在一个文件夹下有很多字段一致,格式统一的数据文件(csv,txt ...
- javadoc 自动生成java帮助文档
用法: javadoc [options] [packagenames] [sourcefiles] 选项: -public 仅显示 public 类和成员 -protected 显示 protect ...
- XXX银行人事管理系统-数据库设计
1. 用户.权限.角色关系用户基本信息 userinfo [人员表]权限表actions[权限表]员工类型表usertype [管理组表]权限映射表actionmapping [权限映射表]权限分栏表 ...
- 简单注册表单--HTML练手项目3【Table】
[本文为原创,转载请注明出处] 技术[HTML] 布局[Table] 步骤1 划分table布局 步骤2 填充内容 文本框+密码框+单选框+复选框+多行文本域+按钮 <input> ...
- 整屏纵向切换超出整屏内容纵向滚动 解决办法-fullpage
这个问题我也是研究了好久,百度了很多办法,swiper我始终没有找到合适的解决办法,所以我放弃了swiper,改用fullpage. fullpage里面有个scrollOverflow的属性: 并且 ...