博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1733 Parity game
阅读量:4703 次
发布时间:2019-06-10

本文共 3770 字,大约阅读时间需要 12 分钟。

Parity game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4587   Accepted: 1799

Description

Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the third to the fifth digit inclusively) and ask him, whether this subsequence contains even or odd number of ones. Your friend answers your question and you can ask him about another subsequence and so on. Your task is to guess the entire sequence of numbers.
You suspect some of your friend's answers may not be correct and you want to convict him of falsehood. Thus you have decided to write a program to help you in this matter. The program will receive a series of your questions together with the answers you have received from your friend. The aim of this program is to find the first answer which is provably wrong, i.e. that there exists a sequence satisfying answers to all the previous questions, but no such sequence satisfies this answer.

Input

The first line of input contains one number, which is the length of the sequence of zeroes and ones. This length is less or equal to 1000000000. In the second line, there is one positive integer which is the number of questions asked and answers to them. The number of questions and answers is less or equal to 5000. The remaining lines specify questions and answers. Each line contains one question and the answer to this question: two integers (the position of the first and last digit in the chosen subsequence) and one word which is either `even' or `odd' (the answer, i.e. the parity of the number of ones in the chosen subsequence, where `even' means an even number of ones and `odd' means an odd number).

Output

There is only one line in output containing one integer X. Number X says that there exists a sequence of zeroes and ones satisfying first X parity conditions, but there exists none satisfying X+1 conditions. If there exists a sequence of zeroes and ones satisfying all the given conditions, then number X should be the number of all the questions asked.

Sample Input

1051 2 even3 4 odd5 6 even1 6 even7 10 odd

Sample Output

3

Source

//脑袋不好使呀,经验不足 #include 
#include
#include
#include
#include
#include
#define N 5677using namespace std;struct node{ int val,next;}ed[N];int h[N];int f[N],s[N];int Find(int x){ if(x!=f[x]) { int tp=Find(f[x]); s[x]^=s[f[x]];//想了一下午才明白为什么这样是对的,因为压缩路径后都直接连到根了,不会再有2次 return f[x]=tp; } return x;}int cnt;int hash(int n){ int e,m=n%N; for(e=h[m];e!=-1;e=ed[e].next) { if(ed[e].val==n) return e; if(ed[e].next==-1) break; } ed[cnt].val=n; ed[cnt].next=h[m]; h[m]=cnt++; return cnt-1;}int xo;bool un(int x,int y){ int rx=Find(x); int ry=Find(y); if(rx!=ry) { f[ry]=rx; s[ry]=s[x]^s[y]^xo; return false; } return true;}int main(){ // freopen("in.txt","r",stdin); int i,n; int len; char op[6]; memset(h,-1,sizeof(h)); int from,to; for(i=0;i<=N;i++) f[i]=i; scanf("%d",&len); scanf("%d",&n); for(i=0;i
#include
#include
#include
#include
using namespace std; #define N 5377 #define M 10002 struct node {    int val;    int next; }E[N]; int v[N]; int cnt; int hsh(int n)//这里不能写hash,会和STL里面hash重到 {     int k=n%N;     for(int e=v[k];e!=-1;e=E[e].next)     {         if(E[e].val==n)            return e;     }     E[cnt].next=v[k];     E[cnt].val=n;     v[k]=cnt++;     return cnt-1; } int F[M],r[M]; int Find(int x) {     if(x!=F[x])     {         int pf=F[x];         F[x]=Find(F[x]);         r[x]=r[x]^r[pf];         return F[x];     }     return x; } int main() {     int len,q;     int a,b;     int i,Xor;     char op[6];     while(scanf("%d",&len),len!=-1)     {       scanf("%d",&q);       cnt=0;       int t=q<<1;       for(i=0;i

转载于:https://www.cnblogs.com/372465774y/archive/2012/08/06/2625360.html

你可能感兴趣的文章
如何适应现代雇佣关系
查看>>
团队项目(第五周)
查看>>
SQL 优化经验总结34条
查看>>
开源 视频会议 收藏
查看>>
核心J2EE模式 - 截取过滤器
查看>>
.net开源CMS
查看>>
JdbcTemplate
查看>>
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>