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-TSQL
一.系统存储过程 常用 sp_helptext --查看可编程性(存储过程.函数.触发器.规则.默认值),表中(约束.触发器) EXEC sp_helptext f_M_Student 二.全局变量 ...
- Appium+python启动虚拟机上的app
查看appPackage和appActivity方法: 1.先在cmd命令行输入 adb logcat ActivityManager:I *:s 2.点击虚拟机启动app即可查看,/前是appPa ...
- 《Mysql 锁 - 概述》
一:锁类型(加锁范围区分类型) - MySQL里面的锁可以分为:全局锁.表级锁.行级锁. 二:全局锁 - 作用 - 对整个数据库实例加锁. - 加锁方式 - MySQL提供加全局读锁的方法:Flus ...
- tcpdump使用的心得
这个linux的抓包工具确实用的不多,这段时间由于处理现场的问题所以就需要这个工具,主要是要知道网卡的信息. 命令就是 tcpdump -i 网卡名
- 怎样给回调函数绑定this
在三种绑定this的方法中, Function.prototype.call() 和 Function.prototye.apply() 都是会立即执行该函数的, 但回调函数是不能立即执行的, 它只是 ...
- (六)Activiti之实现学生请假流程
一.实现学生请假流程 1.1 用activiti插件生成bpmn和png文件 1.2 部署流程定义 package com.shyroke.activiti.firstActiviti; import ...
- 奇妙的算法【4】-汉诺塔&哈夫曼编码
1,汉诺塔问题[还是看了源码才记起来的,记忆逐渐清晰] 汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具.大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着6 ...
- Tomcat 和web 服务器配置
mkdir /usr/local/tomcat # cd /usr/local/tomcat # tar -zxvf /software/apache-tomcat-7.0.54.tar.gz 生成链 ...
- vagrant 搭建开发环境
虚拟机盒子地址 https://app.vagrantup.com/boxes/search vagrant init hirocom/centos7.2vagrant up 修改配置 config. ...
- 超详细的Java面试题总结之JavaWeb基础知识总结
ervlet总结: 在Java Web程序中,Servlet主要负责接收用户请求HttpServletRequest,在doGet(),doPost()中做相应的处理,并将回应HttpServletR ...