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");
}

Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学的更多相关文章

  1. Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力

    B. Rectangle and Square 题目连接: http://codeforces.com/contest/135/problem/B Description Little Petya v ...

  2. Codeforces Beta Round #97 (Div. 1) A. Replacement 水题

    A. Replacement 题目连接: http://codeforces.com/contest/135/problem/A Description Little Petya very much ...

  3. Codeforces Beta Round #97 (Div. 1)

    B 判矩阵的时候 出了点错 根据点积判垂直 叉积判平行 面积不能为0 #include <iostream> #include<cstdio> #include<cstr ...

  4. Codeforces Beta Round #97 (Div. 2)

    A题求给出映射的反射,水题 #include <cstdio> int x,ans[105],n; int main(){ scanf("%d",&n); fo ...

  5. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  6. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  7. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  8. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

随机推荐

  1. python3之线程与进程

    1.CPU运行原理 我们都知道CPU的根本任务就是执行指令,对计算机来说最终都是一串由“0”和“1”组成的序列.CPU从逻辑上可以划分成3个模块,分别是控制单元.运算单元和存储单元,这三部分由CPU内 ...

  2. Linux下实现ping功能

    实现ping功能,就肯定要用到ping命令,那么在Linux下ping命令为: ping [-dfnqrRv][-c<完成次数>][-i<间隔秒数>][-I<网络界面&g ...

  3. Python基础(2):__doc__、文档字符串docString、help()

    OS:Windows 10家庭中文版,Python:3.6.4 Python中的 文档字符串(docString) 出现在 模块.函数.类 的第一行,用于对这些程序进行说明.它在执行的时候被忽略,但会 ...

  4. SpringMVC 返回JSON数据的配置

    spring-mvc-config.xml(文件名称请视具体情况而定)配置文件: <!-- 启动Springmvc注解驱动 --> <mvc:annotation-driven> ...

  5. style一张图--openlayers

  6. eclipse各种报错

    1.控制台报这个错是由于tomcat的session缓存的问题; org.apache.catalina.session.StandardManager doLoad 造成原因:上次未正确关闭tomc ...

  7. UFLDL(五)自编码算法与稀疏性

    新教程内容太繁复,有空再看看,这节看的还是老教程: http://ufldl.stanford.edu/wiki/index.php/%E8%87%AA%E7%BC%96%E7%A0%81%E7%AE ...

  8. mybatis 易百练习笔记

    1. session.commit()  增删改需要提交     session.close()    session需要关闭 2. insert  into t()   values()  不用写i ...

  9. SP_attach_db 添加数据库文件

    SP_attach_db   用法如下:       EXEC   SP_attach_db   @dbname   =   N'目标数据库名',           //这是你要引入后的数据库名. ...

  10. KnockoutJs学习笔记(四)

    由于Writable computed observables和How dependency tracking works的要求相对较高,我先跳过这两篇,学习Pure computed observa ...