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 ...
随机推荐
- [转帖]linux下的find文件查找命令与grep文件内容查找命令
linux下的find文件查找命令与grep文件内容查找命令 https://www.cnblogs.com/shileima/p/8431393.html 在使用linux时,经常需要进行文件查找. ...
- LC 33. Search in Rotated Sorted Array
问题描述 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ...
- WUTOJ 1284: Gold Medal(Java)
1284: Gold Medal 题目 有N个砝码,重量为:3i-1(1<=i<=N),有一块重量为 W 的金牌.现在将金牌放在天平的左边.你需要将砝码放在左边或右边使得天平平衡,如果 ...
- I2C的协议层和物理层
I2C 协议简介 I2C 通讯协议(Inter-Integrated Circuit)是由 Phiilps 公司开发的,由于它引脚少,硬件实现简单,可扩展性强,不需要 USART.CAN 等通讯协议的 ...
- Spring @Transactional注解在什么情况下会失效,为什么?
出处: https://www.cnblogs.com/hunrry/p/9183209.html https://www.cnblogs.com/protected/p/6652188.htm ...
- 学习嵌入式为什么要有uboot(深度解析)
ref:http://www.elecfans.com/d/617674.html 为什么要有uboot 1.1.计算机系统的主要部件 (1)计算机系统就是以CPU为核心来运行的系统. 典型的 ...
- MySQL 常用函数介绍
MySQL 基础篇 三范式 MySQL 军规 MySQL 配置 MySQL 用户管理和权限设置 MySQL 常用函数介绍 MySQL 字段类型介绍 MySQL 多列排序 MySQL 行转列 列转行 M ...
- 利用Filter和HttpServletRequestWrapper实现请求体中token校验
先说一下项目的背景,系统传参为json格式,token为其中一个必传参数,此时如果在过滤器中直接读取request,则后续controller中通过RequestBody注解封装请求参数是会报stre ...
- kafka之基本介绍
什么是kafka? Kakfa起初是由LinkedIn公司开发的一个分布式的消息系统,后成为Apache的一部分,它使用Scala编写,以可水平扩展和高吞吐率而被广泛使用.目前越来越多的开源分布式处理 ...
- Nopcommerce4.2解析——安装
Nopcommerce是一个DotNet领域异常凶残的一个开源电商系统,最先版本4.2,下面我们会逐步分析他的各个模块,为我们的二次开发做准备,应该会写一个系列. 首次运行nop页面会自动跳转到安装页 ...