CodeForces - 1215D Ticket Game
题面
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
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 \(\frac{n}{2}\) digits of this ticket is equal to the sum of the last \(\frac{n}{2}\) 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.
Input
The first line contains one even integer \(n\) \((2 \le n \le 2 \cdot 10^{5})\)— the number of digits in the ticket.
The second line contains a string of \(n\) digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the \(i\)-th character is "?", then the \(i\)-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.
Output
If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).
Examples
input
4
0523
output
Bicarp
input
2
??
output
Bicarp
input
8
?054??0?
output
Bicarp
input
6
???00?
output
Monocarp
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n;
char ch;
int sum1 = 0, sum2 = 0, num1 = 0, num2 = 0;
scanf("%d", &n);
getchar();
for (int i = 0; i < n; ++i) {
scanf("%c", &ch);
if (ch == '?') {
if (i < n / 2) ++num1;
else ++num2;
} else {
if (i < n / 2) sum1 += (ch - '0');
else sum2 += (ch - '0');
}
}
if(num1 == num2 && sum1 != sum2)
{
puts("Monocarp");
return 0;
}
if(num1 == 0 && num2 == 0)
{
if(sum1 == sum2)puts("Bicarp");
else puts("Monocarp");
return 0;
}
if(sum1 == sum2){
if(num1 == num2)puts("Bicarp");
else puts("Monocarp");
}else{
if((num2 - num1)/2*9 == (sum1 - sum2)) puts("Bicarp");
else puts("Monocarp");
}
}
原文地址:https://www.cnblogs.com/YY666/p/11652382.html
- Android Studio 使用Gradle多渠道打包
- 某些浏览器中因cookie设置HttpOnly标志引起的安全问题
- 偷懒新姿势,打造属于RecyclerView的万能适配器Adapter和ViewHolder
- 科普哈希长度扩展攻击(Hash Length Extension Attacks)
- 分析 WordPress 3.8.2 修復的cookie偽造漏洞
- 技术宅打造全能美剧播放器
- 判断是否支持Heartbeat的NSE脚本
- [原创]Fluent NHibernate之旅二--Entity Mapping
- [原创]Fluent NHibernate之旅(三)-- 继承
- Web应用手工渗透测试——用SQLMap进行SQL盲注测试
- IIS4\IIS5 CGI环境块伪造0day漏洞
- [原创]Fluent NHibernate之旅(四)-- 关系(上)
- 基于流量的OpenSSL漏洞利用检测方法
- [原创]Fluent NHibernate之旅(四)-- 关系(中)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 检查图片是否损坏、图片后缀是否与实际图片类型对应 - Python
- 规则引擎 - drools 使用讲解(简单版) - Java
- Python奇技淫巧 - 持续更新中....
- 150+行Python代码实现带界面的数独游戏
- Python实现十大经典排序算法
- 140行Python代码实现Flippy Bird
- 200行Python代码实现贪吃蛇
- 简单说维特比算法 - python实现
- Android绘图及Bitmap几个知识点整理
- Spark Pipeline官方文档
- Python-时间及日期-07-获取本周或上周几具体日期
- Spark Job-Stage-Task实例理解
- 想查看微信好友撤回的消息?Python帮你搞定
- MySQL 案例:同步中断与SQL线程类型转换
- Android端Charles抓包