Educational Codeforces Round 90 (Rated for Div. 2) B. 01 Game(字符串博弈)
题目链接: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)}$ 模拟。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
string s; cin >> s;
int cnt = 0;
while (1) {
bool flag = false;
for (int i = 0; i + 1 < s.size(); i++) {
if (s[i] != s[i + 1]) {
s = s.substr(0, i) + s.substr(i + 2);
++cnt;
flag = true;
}
}
if (!flag) break;
}
cout << (cnt & 1 ? "DA" : "NET") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
题解二
在移除所有相邻的不同字符后,字符串最终为连续的 $0$ 或 $1$,即移除了 $0$ 和 $1$ 中的较少者,其个数代表着游戏总共可以进行多少步。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
string s; cin >> s;
int cnt[2] = {};
for (char c : s)
++cnt[c - '0'];
int mi = min(cnt[0], cnt[1]);
cout << (mi & 1 ? "DA" : "NET") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
Educational Codeforces Round 90 (Rated for Div. 2) B. 01 Game(字符串博弈)的更多相关文章
- 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$,可以进行一次反 ...
- Educational Codeforces Round 90 (Rated for Div. 2) C. Pluses and Minuses(差分)
题目链接:https://codeforces.com/contest/1373/problem/C 题意 给出一个只含有 $+$ 或 $-$ 的字符串 $s$,按如下伪代码进行操作: res = 0 ...
- Educational Codeforces Round 90 (Rated for Div. 2) A. Donut Shops(数学)
题目链接:https://codeforces.com/contest/1373/problem/A 题意 有两种包装的甜甜圈,第一种 $1$ 个 $a$ 元,第二种 $b$ 个 $c$ 元,问买多少 ...
- 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 ...
- Educational Codeforces Round 73 (Rated for Div. 2)E(思维,博弈)
//这道题博弈的核心就是不能让后手有一段只能放b而长度不够放a的段,并且先手要放最后一次#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h> ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
随机推荐
- TR2021_0000偶发数据库连接异常问题排查
[问题描述] 数据库连接异常是很难排查的一类问题.因为它牵涉到应用端,网络层和服务器端.任何一个组件异常,都会导致数据库连接失败.开发遇到数据库连接不上的问题,都会第一时间找DBA来协助查看,DBA除 ...
- 对于k8s微服务的性能测试监控平台搭建
之前有写过对于传统项目的性能测试监控,但是对于目前市场占比已经很低,大部分项目使用k8s,今天讲一下对于k8s如何去监控. 对于k8s的监控我们所有的操作都要在master下进行. 一.部署grafa ...
- Flutter 布局类组件:线性布局(Row和Column)
前言 所谓线性布局,即指沿水平或垂直方向排布子组件.Flutter中通过Row和Column来实现线性布局,并且它们都继承自弹性布局(Flex). 接口描述 Row({ Key key, // 表示子 ...
- Java类的加载过程-重点!!
java类的加载过程有以下几步共同完成: 加载->连接->初始化.连接又分为验证.准备.解析 一个非数组类的加载阶段(加载阶段获取类的二进制字节流的动作)是可控性最强的阶段,这一步我们可以 ...
- 【Docker】Docker启动停止重启 Redirecting to /bin/systemctl start docker.service
[root@liuawen local]# docker -v Docker version 1.13.1, build cccb291/1.13.1 [root@liuawen local]# 启动 ...
- 【Git】3、创建Git版本库、配置Git仓库用户邮箱信息
初识Git 文章目录 初识Git 1.创建Git版本库 认识.git 2.基础配置 2.1.查看配置信息 2.2.配置昵称邮箱信息 2.3.修改配置信息 1.通过命令行 2.通过修改配置文件. 修改全 ...
- /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh: line 19: mysql: command not found
[root@test ~]# tail -f /tmp/zabbix_agentd.log /var/lib/zabbix/percona/scripts/get_mysql_stats_wrappe ...
- 【Linux】shell脚本实现多并发
情景 shell脚本的执行效率虽高,但当任务量巨大时仍然需要较长的时间,尤其是需要执行一大批的命令时.因为默认情况下,shell脚本中的命令是串行执行的.如果这些命令相互之间是独立的,则可以使用&qu ...
- poj-Decoding Morse Sequences(动态规划)
Description Before the digital age, the most common "binary" code for radio communication ...
- 1.8V转5V电平转换芯片,1.8V转5V的电源芯片
1.8V是一个比较低的电压,在电压供电电压中,1.8V电压的过于小了,在一些电子模块或者MCU中,无法达到供电电压,和稳压作用,PW5100就是可以在1.8V转5V的电平转换电路和芯片,最大可提供50 ...