Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学

时间:2020-12-05 02:29:56

C. Zero-One

题目连接:

http://codeforces.com/contest/135/problem/C

Description

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).

Sample Input

????

Sample Output

00

01

10

11

题意

A和B 在玩一个游戏

一开始给你一个01串,A的目的是使得这个串最后变得最小,B的目的是使得这个串变得最大

然后A先手,玩到这个串长度为2之后,就结束了

?的位置就是可0,可1

问你最后的可能性有哪些。

题解:

A每次操作是删除最前面的1

B的操作是删除最前面的0

00和11的情况很简单

01其实就是10反过来,只要会判断其中一个就好了

01的话,我们找到最末尾的一个数,因为这个数肯定会被留下来,然后我们看这个数是不是1

然后再check前面的最差情况会不会剩下0就好了

这个是数学,推一推就好了……

现在有x个1,y个0,z个问号,然后莽一波……

代码

#include<bits/stdc++.h>
using namespace std;
int flag[4],x,y,z;
string s,s1,s2;
bool check01()
{
s1=s;int len=s.size();
if(s1[len-1]=='0')return false;
x=0,y=0,z=0;
for(int i=0;i<len-1;i++)
{
if(s[i]=='1')x++;
if(s[i]=='0')y++;
if(s[i]=='?')z++;
}
x++;
if(x-(z+y)>=2)return false;
if(y-(x+z)>=1)return false;
return true;
}
bool check10()
{
s1=s;int len=s.size();
if(s1[len-1]=='1')return false;
x=0,y=0,z=0;
for(int i=0;i<len-1;i++)
{
if(s[i]=='1')x++;
if(s[i]=='0')y++;
if(s[i]=='?')z++;
}
y++;
if(x-(z+y)>=2)return false;
if(y-(x+z)>=1)return false;
return true;
}
int main()
{
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='1')x++;
if(s[i]=='0')y++;
if(s[i]=='?')z++;
}
if(x+z-y>=2)flag[0]=1;
if(y+z-x>=1)flag[1]=1;
if(check01())flag[2]=1;
if(check10())flag[3]=1;
if(flag[1])printf("00\n");
if(flag[2])printf("01\n");
if(flag[3])printf("10\n");
if(flag[0])printf("11\n");
}