Codeforces 135C Zero-One(博弈)

原创 2018年04月16日 16:11:50

C. Zero-One
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.

Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card contains a digit: 0 or 1. Players move in turns and Masha moves first. During each move a player should remove a card from the table and shift all other cards so as to close the gap left by the removed card. For example, if before somebody's move the cards on the table formed a sequence 01010101, then after the fourth card is removed (the cards are numbered starting from 1), the sequence will look like that: 0100101.

The game ends when exactly two cards are left on the table. The digits on these cards determine the number in binary notation: the most significant bit is located to the left. Masha's aim is to minimize the number and Petya's aim is to maximize it.

An unpleasant accident occurred before the game started. The kids spilled juice on some of the cards and the digits on the cards got blurred. Each one of the spoiled cards could have either 0 or 1 written on it. Consider all possible variants of initial arrangement of the digits (before the juice spilling). For each variant, let's find which two cards are left by the end of the game, assuming that both Petya and Masha play optimally. An ordered pair of digits written on those two cards is called an outcome. Your task is to find the set of outcomes for all variants of initial digits arrangement.

Input

The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, inclusive.

Output

Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the first sample).

Examples
input
Copy
????
output
Copy
00
01
10
11
input
Copy
1010
output
Copy
10
input
Copy
1?1
output
Copy
01
11
Note

In the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will contain all 4 possible outcomes.

In the third sample only 2 variants of numbers arrangement are possible: 111 and 101. For the variant 111 the outcome is 11. For the variant 101 the outcome is 01, because on the first turn Masha can remove the first card from the left after which the game will end.


【题目链接】点击有惊喜

【题意】有一个长度为n的字符串,字符串由0,1,?组成,?即可能是0也可能是1,有A,B两个选手一次取字符串,每次只能够取一个(如果取完后字符串分成两部分则再拼接起来),A的目的是使的01字符串对应的十进制最小,B的目的是使的01字符串对应的十进制最大,最后剩01串长度为2时截止。

【思路】设one为字符串中1的个数,zero为字符串中0的个数。通过一个例子可以发现以下规律,当字符串中不存在?时,zero>one 最后输出的为"00",当one>zero+1时,输出"11,当zero==one || one == zero+1 的时候,如果字符串的最后一个字符为0,则输出 "10"。

对于当字符串中存在?时,思考的方式也一样。

【代码如下】

#include <bits/stdc++.h>
using namespace std;

int main(){
    string str;
    cin >> str;
    int n = str.length();
    int zero=0,one=0,other=0;
    for(int i = 0; i < n; i ++) if(str[i]=='0') zero++; else if(str[i]=='1') one++; else other++;
    int p = n/2-1, q = (n+1)/2-1;
    if(one <= q) puts("00");
    if(str[n-1] != '0' && zero-1 <= p && one+(str[n-1]=='?')-1 <= q) puts("01");
    if(str[n-1] != '1' && zero+(str[n-1]=='?')-1<=p && one-1<=q) puts("10");
    if(zero <= p) puts("11");
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/i1020/article/details/79960827

CodeForces 135C C. Zero-One

题目 题意: 一个01串,AB两个人轮流删去一个字符,直到只剩两个,A先手。最后剩的两位组成一个二进制数,A要使其最小,B要使其最大。 有一些部分不知道原来是什么,用?表示,求所有的可能里,最后剩下的...
  • u010638776
  • u010638776
  • 2013-08-09 20:23:39
  • 833

codeforces 455B(博弈+dp)

题目链接:codeforces 455B题目大意:给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符串是给定的任意一个字符串的前缀,不能操作时为输,赢...
  • qq_24451605
  • qq_24451605
  • 2015-09-22 10:01:19
  • 1067

Codeforces 603C 博弈论 + 关于博弈论理解

CF 603C 题目链接: http://codeforces.com/problemset/problem/603/C 题意: 给n个数(n
  • beihai2013
  • beihai2013
  • 2015-12-04 19:39:16
  • 428

codeforces 768 E Game of Stones(博弈)

题意: 算是nim的变形题吧 给n堆石子,在一堆石头上取的石头数量只能去一次,比如你在一堆石子上取了了4个石子,那么接下里你就不能在这堆石子上取4个石子了.问后手是否必胜. 结题思路: 如果没有最...
  • johsnows
  • johsnows
  • 2017-02-21 11:17:05
  • 437

[CodeForces 595C] Warrior and Archer (无胜负最优值博弈)

CodeForces - 595C 题意是一根数轴上分布着偶数个点,A和 B每次轮流从上面拿走一个点 A希望最后剩下来的两个点距离尽量近,B则希望尽量远 若两个人都采用最佳策略,则最后剩下的两个...
  • u012015746
  • u012015746
  • 2016-04-26 17:59:57
  • 253

codeforces 399 E. Game of Stones 博弈 思维题

题目地址http://codeforces.com/contest/768/problem/E题意有1
  • dpppBR
  • dpppBR
  • 2017-02-22 17:26:39
  • 418

CodeForces 547E Mike and Friends [后缀树组+主席树]

给出N个串,M个询问,对于每个询问L,R,K,给出串L到串R的所有串中串K作为子串出现了几次。...
  • GrassTreeFlower
  • GrassTreeFlower
  • 2016-02-27 20:30:52
  • 786

Codeforces 918D - MADMAX 【记忆化搜索+博弈】

Codeforces 918D - MADMAX 【记忆化搜索+博弈】 As we all know, Max is the best videogame player among her frien...
  • my_sunshine26
  • my_sunshine26
  • 2018-02-21 23:04:44
  • 85

CodeForces 299 C.Weird Game(博弈论)

Description 两个长度为2n的01串,两个人轮流开始取数字,每次只能取两个人之前都没取过的位置的数字,n次后两个人就得到了两个长度为n的数字,谁的数字大谁赢,两个人足够机智,问是先手必胜还...
  • V5ZSQ
  • V5ZSQ
  • 2017-07-15 17:24:03
  • 278

CodeForces 595C Warrior and Archer(贪心博弈)

题意: 给一个数组,A和B轮流去除一个元素直到剩下最后两个元素,A希望这两个元素的差值尽可能小,B希望这两个元素的差值尽可能大。求最终的差值。 思路: 假设最终剩下的坐标是l和r,那么A选的肯定是[l...
  • exp1ore
  • exp1ore
  • 2017-08-23 17:17:13
  • 110
收藏助手
不良信息举报
您举报文章:Codeforces 135C Zero-One(博弈)
举报原因:
原因补充:

(最多只允许输入30个字)