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 ...
随机推荐
- 聊天室(下篇)GatewayWorker 与 Laravel 的整合
思路 上一篇大概梳理了一下 GatewayWorker 的基础知识.这篇就来准备整合 GatewayWorker 到 Laravel. GatewayWorker 是基于 Socket 监听的服务器框 ...
- 解决Win7&Win8 64位下Source Insight提示未完整安装的问题[转]
转自:http://www.cnblogs.com/sixiweb/p/3421533.html 网上的破解版的注册表文件都是针对32位系统的,所以在64位系统里运行根本无法破解.下面分别贴出这俩系统 ...
- Django集成Xadmin list index out of range报错解决方案
return self.render(context) File "C:\Python36\lib\site-packages\django\template\defaulttags.py& ...
- AdvStringGrid 获取值
stringGrid.row stringgrid.col分别为当前行和列 stringGrid.cells[stringgrid.col,stringGrid.row]就是当前cell的值 ---- ...
- Writing a Kernel in C++
*:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...
- MySQL慢查询优化
MySQL数据库是常见的两个瓶颈是CPU和I/O的瓶颈,CPU在饱和的时候一般发生在大量数据进行比对或聚合时.磁盘I/O瓶颈发生在装入数据远大于内存容量的时候,如果应用分布在网络上,那么查询量相当大的 ...
- ueditor初始化
一.下载文件复制到项目中 二.复制表情文件 三.复制列表图片 四.修改ueditor.config.js文件 五.接着修改net文件下config.json文件 六.完蛋了,不支持IE8,版本替换为了 ...
- 【LOJ】#2066. 「SDOI2016」墙上的句子
题解 我一直也不会网络流--orz 我们分析下这道题,显然和行列没啥关系,就是想给你n + m个串 那么我们对于非回文单词之外的单词,找到两两匹配的反转单词(即使另一个反转单词不会出现也要建出来) 具 ...
- 【51nod】1123 X^A Mod B (任意模数的K次剩余)
题解 K次剩余终极版!orz 写一下,WA一年,bug不花一分钱 在很久以前,我还认为,数论是一个重在思维,代码很短的东西 后来...我学了BSGS,学了EXBSGS,学了模质数的K次剩余--代码一个 ...
- Loadrunner参数化逗号报错解决方法
Loadrunner参数化逗号报错解决方法 介绍Loadrunner参数化时,参数中包含有逗号时出错的解决方法. 在Loadrunner进行参数化时,参数中如果含有逗号,编辑保存后会报错: 此 ...