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. 华硕笔记本U盘重装系统

    ESC启动把Secure Boot改为Disabled,Launch CSM改为Enabled,然后重新选择不带UEFI字样的U盘启动项.然后就可以找到U盘进入PE

  2. mvc 分部视图(Partial)显示登陆前后变化以及Shared文件夹在解决方案资源管理器中没有显示的问题

    刚开始我的解决方案资源管理器中没有显示Shared文件夹,但Shared文件夹在项目中是实际存在的,我搜了下好像没有类似的解答(可能是我搜索的关键词不够准确).后来自己看了下vs2012. 其实解决方 ...

  3. 21 JSON and Go go语言和json

    JSON and Go 25 January 2011 Introduction JSON (JavaScript Object Notation) is a simple data intercha ...

  4. 缓存数据库-redis安装和配置

    一:redis安装 python操作redis分为两部分,一为安装redis程序 二是安装支持python操作redis的模块 1)安装redis redis 官方网站:http://www.redi ...

  5. python网络编程--进程线程

    一:什么是进程 一个程序执行时的实例被称为一个进程. 每个进程都提供执行程序所需的资源.一个进程有一个虚拟地址空间.可执行代码.对系统对象的开放句柄.一个安全上下文.一个独特的进程标识符.环境变量.一 ...

  6. 字体格式类型(.eot/.otf/.woff/.svg)

    @font-face语句是css中的一个功能模块,用于实现网页字体多样性的模块(设计者可随意指定字体,不需要考虑浏览者电脑上是否安装). @font-face文件 而由于网页中使用的字体类型,也是各浏 ...

  7. git —— 分支冲突

    解决冲突 冲突需手动解决 $ git status 查看冲突的文件 <<<<<<<,=======,>>>>>>> ...

  8. 用戶登陸。防SQL注入,驗證碼不區分大小寫。。

    if (string.Compare(TBCheckCode.Text, Session["CheckCodeI"].ToString(), true) == 0)        ...

  9. dubbo的详细介绍

    1.背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 2.架构 单一应用架构 当网站流量很 ...

  10. console在ie下不兼容的问题(console在ie9下阻碍页面的加载,打开页面一片空白)

    在页面中加入以下代码: window.console = window.console || (function() { var c = {}; c.log = c.warn = c.debug = ...