Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学
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 数学的更多相关文章
- 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 ...
- Codeforces Beta Round #97 (Div. 1) A. Replacement 水题
A. Replacement 题目连接: http://codeforces.com/contest/135/problem/A Description Little Petya very much ...
- Codeforces Beta Round #97 (Div. 1)
B 判矩阵的时候 出了点错 根据点积判垂直 叉积判平行 面积不能为0 #include <iostream> #include<cstdio> #include<cstr ...
- Codeforces Beta Round #97 (Div. 2)
A题求给出映射的反射,水题 #include <cstdio> int x,ans[105],n; int main(){ scanf("%d",&n); fo ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- 搭建本地git服务器
最近因为项目需求,需要实现一个原型系统,加上后期项目需要多人协作,考虑采用了git做版本控制. 这里主要简要描述下git服务器和客户端的搭建和配置. 1.git服务器 (1)安装git sudo ap ...
- PHP 生成、识别二维码及安装相关扩展/工具
2018-02-20 00:30:26 更新:推荐新扩展(极力推荐) 这篇文章里用的两个二维码扩展都有些问题和麻烦:phpqrcode(生成二维码)的源码有点小 bug: 而 php-zbarcod ...
- 一步一步搭建oracle 11gR2 rac+dg之环境准备(二)【转】
一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之环境准备 (二) 一步一步搭建oracle 11gR2 rac+dg之环境准备 ...
- LeetCode282. Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add bin ...
- Linux学习笔记:wc查看文件字节数、字数、行数
Linux系统中的wc(Word Count)命令可以统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 若不指定文件名称,或是所给予的文件名为“-”,则wc指令会从标准输入设备读取数据. 语 ...
- Tensorflow之训练MNIST(1)
先说我遇到的一个坑,在下载MNIST训练数据的时候,代码报错: urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FA ...
- Kotlin尝试
Kotlin 是一种静态类型的编程语言,可在 Java 虚拟机上运行,也可以编译为 JavaScript 源代码.其主要发展来自位于俄罗斯圣彼得堡的 JetBrains 程序员团队.虽然语法与 Jav ...
- python学习day4软件目录结构规范
为什么要设计好目录结构? 参考:http://www.cnblogs.com/alex3714/articles/5765046.html "设计项目目录结构",就和"代 ...
- C语言:10个整数排序(别忘了负数)
题目内容: 10个整数排序(别忘了负数) 例如 input 1 0 2 0 3 4 1 9 8 7 output 0 0 1 1 2 3 4 7 8 9 编码: void sort(int *a); ...
- MVC文件上传
这次来看下一个MVC网站上传文件的功能,其中上传用到uploadify这个jquery插件,网上还有很多类似的,哪种都无所谓,能实现功能便行,貌似uploadify官网上的这个插件是要付费的,这里就顺 ...