CodeFoeces 1215 D Ticket Game

题目大意

M和B轮流玩游戏(每一轮M先手

现在给出一个长度为偶数的串,包含字符'?'和数字

现在两人依次在'?'上填数字\(0\)~\(9\)

若M先手,最后串的左右两部分数字之和相等,则B赢,反之M赢

solution

难得教练给一道稍稍简单的题QwQ

最好想的状态就是:

  • 若一开始左边的和等于右边的和

    • 若左边的'?'数量等于右边的,那么每次M放一个数字,B放一个同样的,显然B赢
    • 反之,两边的'?'数量不相等,那么先手赢
  • 若一开始两边的和不相等

    • 如果大的一边'?'较多,那么先手必胜,因为后手不可缩小差距
    • 反之,则就需要讨论一下了,前“小”次按照保持差距去放,然后剩下的次数,也就是两边个数之差,下面后手的任务就是缩小差距那么每次补齐9即可,也就是说,相差的数字除了B放的数字要求能被9整除,那么后手赢。反之,先手赢。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=2e5+5;
int n;
char s[maxn];
int ls, rs, x, y; int main(){
scanf("%d", &n);
scanf("%s", s + 1);
for(int i = 1; i <= n / 2; i++){
if(s[i] == '?') x++;
else ls += s[i] - '0';
}
for(int i = n / 2 + 1; i <= n; i++){
if(s[i] == '?') y++;
else rs += s[i] - '0';
}
if(ls<rs){
swap(ls, rs);
swap(x, y);
}
if(ls == rs){
printf("%s\n", x == y? "Bicarp":"Monocarp");
}
else{
if(x >= y) printf("Monocarp\n");
else printf("%s\n", (y - x) % 2 == 0 && ls - rs == (y - x)/2*9? "Bicarp":"Monocarp");
}
return 0;
}

最新文章

  1. xcode 第三方插件遇到问题
  2. oracle 存储过程的写法
  3. windows phone上下文菜单ContextMenu的使用示例
  4. const int *p与int *const p的区别(转:csdn,suer0101)
  5. Android构建boot.img(二):kernel的拷贝与打包
  6. Web内容管理系统 Magnolia 介绍-挖掘优良的架构(1)
  7. [Redux] Writing a Todo List Reducer (Toggling a Todo)
  8. django: db howto - 1
  9. Android 文件操作之openFileOutput
  10. 高性能浏览器网络(High Performance Browser Networking) 第二章
  11. 去掉tomcat中appBase默认的ROOT
  12. java里Struts2学习登录练习详解
  13. 【数据结构】算法 LinkList (Merge Two Sorted Lists)
  14. Rime 小狼毫 注意事项
  15. Windows10下virtualenv配置
  16. Linux系统中安装使用百度云网盘
  17. socketsever
  18. jQuery 文件上传插件:uploadify、swfupload
  19. C语言 &#183; 三角形
  20. python 操作 mysql 数据库 datetime 属性字段为 0000-00-00 00:00:00 的问题

热门文章

  1. 不可不知的JSON处理库(cJSON)
  2. Python--函数&amp;过程
  3. 关于Java优质代码的那些事
  4. SSM框架处理跨域问题
  5. Linux dd工具磁盘读写测试分析
  6. @bzoj - 1921@ [ctsc2010]珠宝商
  7. TensorFlow从0到1之TensorFlow常用激活函数(19)
  8. 阿里P7终于讲完了JDK+Spring+mybatis+Dubbo+SpringMvc+Netty源码
  9. cb45a_c++_STL_算法_删除_(3)_unique(唯一的意思)删除连续性的重复的数据
  10. Wireshark论证TCP3次握手的过程