首页 技术 正文
技术 2022年11月15日
0 收藏 385 点赞 3,569 浏览 1422 个字

链接:

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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844