题目链接:https://codeforces.com/contest/1373/problem/B

题意

给出一个二进制串 $s$,Alica 和 Bob 每次可以选择移去 $s$ 中的一个 $10$ 或 $01$,无法选择者视为输掉游戏,判断最终谁会胜利。($1 \le t \le 1000, 1 \le |s| \le 100$)

题解一

$s$ 范围较小,$O_{(n^2)}$ 模拟。

代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. string s; cin >> s;
  6. int cnt = 0;
  7. while (1) {
  8. bool flag = false;
  9. for (int i = 0; i + 1 < s.size(); i++) {
  10. if (s[i] != s[i + 1]) {
  11. s = s.substr(0, i) + s.substr(i + 2);
  12. ++cnt;
  13. flag = true;
  14. }
  15. }
  16. if (!flag) break;
  17. }
  18. cout << (cnt & 1 ? "DA" : "NET") << "\n";
  19. }
  20.  
  21. int main() {
  22. int t; cin >> t;
  23. while (t--) solve();
  24. }

题解二

在移除所有相邻的不同字符后,字符串最终为连续的 $0$ 或 $1$,即移除了 $0$ 和 $1$ 中的较少者,其个数代表着游戏总共可以进行多少步。

代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. string s; cin >> s;
  6. int cnt[2] = {};
  7. for (char c : s)
  8. ++cnt[c - '0'];
  9. int mi = min(cnt[0], cnt[1]);
  10. cout << (mi & 1 ? "DA" : "NET") << "\n";
  11. }
  12.  
  13. int main() {
  14. int t; cin >> t;
  15. while (t--) solve();
  16. }

Educational Codeforces Round 90 (Rated for Div. 2) B. 01 Game(字符串博弈)的更多相关文章

  1. Educational Codeforces Round 90 (Rated for Div. 2) D. Maximum Sum on Even Positions(dp)

    题目链接:https://codeforces.com/contest/1373/problem/D 题意 给出一个大小为 $n$ 的数组 $a$,下标为 $0 \sim n - 1$,可以进行一次反 ...

  2. Educational Codeforces Round 90 (Rated for Div. 2) C. Pluses and Minuses(差分)

    题目链接:https://codeforces.com/contest/1373/problem/C 题意 给出一个只含有 $+$ 或 $-$ 的字符串 $s$,按如下伪代码进行操作: res = 0 ...

  3. Educational Codeforces Round 90 (Rated for Div. 2) A. Donut Shops(数学)

    题目链接:https://codeforces.com/contest/1373/problem/A 题意 有两种包装的甜甜圈,第一种 $1$ 个 $a$ 元,第二种 $b$ 个 $c$ 元,问买多少 ...

  4. Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)

    D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...

  5. Educational Codeforces Round 73 (Rated for Div. 2)E(思维,博弈)

    //这道题博弈的核心就是不能让后手有一段只能放b而长度不够放a的段,并且先手要放最后一次#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h> ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  7. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  8. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  9. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

随机推荐

  1. Spark推荐系统实践

    推荐系统是根据用户的行为.兴趣等特征,将用户感兴趣的信息.产品等推荐给用户的系统,它的出现主要是为了解决信息过载和用户无明确需求的问题,根据划分标准的不同,又分很多种类别: 根据目标用户的不同,可划分 ...

  2. php利用腾讯ip分享计划获取地理位置示例分享

    <?php function getIPLoc_QQ($queryIP){ $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$quer ...

  3. Centos 7 下的KVM虚拟机

    一 什么是KVM虚拟机: KVM虚拟机 Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中. ...

  4. Logrotate工具使用

    Logrotate ​ logrotate是一个被设计来简化系统管理日志文件的工具,在系统运行时,如果产生大量的日志文件,可以使用该工具进行管理,如/var/log/*文件夹是存储系统和应用日志的目录 ...

  5. Python基础语法3-输入、输出语句

  6. ubuntu 上搭建 go的开发环境 vscode

    原文链接: https://astaxie.gitbooks.io/build-web-application-with-golang/zh/01.4.html 原本我是在windows下进行go的环 ...

  7. 【Oracle】迁移表到其他的表空间

    有些时候需要将表迁移到其他的表空间,在将表空间做相关的操作 下面是命令如何迁移表空间 SQL> alter table 表名 move tablespace 表空间名; 如果有很多的表想要迁移的 ...

  8. LeetCode590. N叉树的后序遍历

    题目 1 class Solution { 2 public: 3 vector<int>ans; 4 vector<int> postorder(Node* root) { ...

  9. 写给 Linux 初学者的一封信

    大家好,我是肖邦. 这篇文章是写给 Linux 初学者的,我会分享一些作为初学者应该知道的一些东西,这些内容都是本人从事 Linux 开发工作多年的心得体会,相信会对初学者有所帮助.如果你是 Linu ...

  10. USB限流IC,输入5V,输出5V,最大3A限流

    USB限流芯片,5V输入,输出5V电压,限流值可以通过外围电阻进行调节,PWCHIP产品中可在限流范围0.4A-4.8A,并具有过压关闭保护功能. 过压关闭保护: 如芯片:PW1555,USB我们一半 ...