Parity game---poj1733
Description
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
Output
Sample Input
10
5
1 2 even
3 4 odd
5 6 even
1 6 even
7 10 odd
Sample Output
3 题意:有一个长度为n的01串,有m句话,每句话说明x到y之间是有奇数(odd)个1还是偶数(even)个1;求的是前几句话是真的;如果全部为真输出m; 每输入一句话时,可以判断是否和之前的话相冲突,用r[i]表示i到i的跟节点之间1的个数是偶数还是奇数,1表示奇数,0代表偶数; 本题的n是10亿,所以不能定义一个10亿的数组;用map<int,int>定义就行
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<map>
#define N 105
#define INF 0xfffffff
using namespace std; //int f[N], r[N];//r[i]代表i到i的跟节点之间的关系;
map<int,int> f;
map<int,int> r; int Find(int x)
{
if(!f[x])
return x;
int k = f[x];
f[x] = Find(f[x]);
r[x] = (r[x]+r[k])%;
return f[x];
}
int main()
{
int px, py, flag, ans, i, n, m, x, y, d;
char str[];
while(scanf("%d", &n)!=EOF)
{
flag = ;
f.clear();
r.clear();
scanf("%d", &m);
for(i = ; i <= m; i ++)
{
scanf("%d%d%s", &x, &y, str);
x--;
if(str[] == 'e')//偶数是0;奇数是1;
d = ;
else
d = ;
px = Find(x);
py = Find(y);
if(px != py)
{
f[px] = py;
r[px] = (r[y] + d - r[x] +)%;//画向量图找关系;
}
else if(flag== && ( + r[x]-r[y])% != d)
{
flag = ;
ans = i;
}
}
if(flag==)//如果全部都正确的话输出m;-_-在这wa了一次;
ans=m+;
printf("%d\n", ans-);
}
return ;
}
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<map>
#define N 105
#define INF 0xfffffff
using namespace std; //int f[N], r[N];//r[i]代表i到i的跟节点之间的关系;
map<int,int> f;
map<int,int> r; int Find(int x)
{
if(!f[x])
return x;
int k = f[x];
f[x] = Find(f[x]);
r[x] = (r[x]+r[k])%;
return f[x];
}
int main()
{
int px, py, flag, ans, i, n, m, x, y, d;
char str[];
while(scanf("%d", &n)!=EOF)
{
flag = ;
f.clear();
r.clear();
scanf("%d", &m);
for(i = ; i <= m; i ++)
{
scanf("%d%d%s", &x, &y, str);
x--;
if(str[] == 'e')//偶数是0;奇数是1;
d = ;
else
d = ;
px = Find(x);
py = Find(y);
if(px < py)
{
f[px] = py;
r[px] = (r[y] + d - r[x]+)%;//画向量图找关系;
}
else if(px > py)
{
f[py] = px;
r[py] = (r[x] - r[y] - d + )%;
} else if(px==py &&flag== && (r[y] - r[x] + )% != d)
{
flag = ;
ans = i;
}
}
if(flag==)//如果全部都正确的话输出m;-_-在这wa了一次;
ans=m+;
printf("%d\n", ans-);
}
return ;
}
Parity game---poj1733的更多相关文章
- POJ1733 Parity game 【扩展域并查集】*
POJ1733 Parity game Description Now and then you play the following game with your friend. Your frie ...
- POJ1733 Parity game 【带权并查集】*
POJ1733 Parity game Description Now and then you play the following game with your friend. Your frie ...
- 【POJ1733】Parity game
[POJ1733]Parity game 题面 vjudge 题解 比较简单的分类并查集 将一个查询操作看作前缀和\(s_r-s_{l-1}\)的奇偶性 将每个点拆成一奇一偶然后分别连边即可 如果一个 ...
- 【poj1733】 Parity game
http://poj.org/problem?id=1733 (题目链接) 题意 一个由0,1组成的序列,每次给出一段区间的奇偶,问哪一条信息不合法. Solution 并查集. 题目中序列的长度有很 ...
- 【POJ1733】【带标记并查集】Parity game
Description Now and then you play the following game with your friend. Your friend writes down a seq ...
- POJ1733 Parity game
题意 Language:Default Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13833 Acc ...
- poj1733 Parity Game(扩展域并查集)
描述 Now and then you play the following game with your friend. Your friend writes down a sequence con ...
- POJ1733:Parity Game(离散化+带权并查集)
Parity Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12853 Accepted: 4957 题目链接 ...
- POJ1733 Parity game —— 种类并查集
题目链接:http://poj.org/problem?id=1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 【poj1733】Parity game--边带权并查集
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15776 Accepted: 5964 Description Now ...
随机推荐
- NUC972裸机调试步骤
.将开发板设置成USB启动.开发板拨码开关与启动方式设置对应如下: 其中PA1 ,PA0对应S1和S0 上电或复位,使开发板从USB启动.开启NuWriter,选择正确的芯片型号,按下“Continu ...
- React Native(十三)——ios键盘挡住textInput
渐入佳境 用React Native重构的项目也快接近尾声,剩下的就是适配ios的功能了.慢慢地也从中琢磨出了一点门道,于是就遇见了键盘遮挡textInput问题斑斑: 正常页面: android点击 ...
- 如何将一个项目打成war包?
如何将一个项目打成war包?进入该项目所在目录jar -cvf myProjec.war myProject
- SQL - 根据天来分组比较
SELECT COUNT(*) FROM (SELECT WeixinUserID,CONVERT(varchar(100),CreateTime, 23) AS DT FROM SiteVisite ...
- [转]java中判断字符串是否为数字的三种方法
1用JAVA自带的函数public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ ...
- 使用Phoenix通过sql语句更新操作hbase数据
hbase 提供很方便的shell脚本,可以对数据表进行 CURD 操作,但是毕竟是有一定的学习成本的,基本上对于开发来讲,sql 语句都是看家本领,那么,有没有一种方法可以把 sql 语句转换成 h ...
- 跨域 - jsonp轻松搞定跨域请求
1.jsonp轻松搞定跨域请求 vue中使用axios,遇到跨域我就蒙逼了.第一次真正意义上的尝试使用jsonp js中用 var myscript = document.createElement( ...
- 微信小程序插件内页面跳转和参数传递(转)
在此以插件开发中文章列表跳传文章详情为例. 1.首先在插件中的文章列表页面wxml中绑定跳转事件. bindtap='url' data-id="{{item.article_id}}&qu ...
- EGL 1.0 学习笔记
http://hi.baidu.com/leo_xxx/item/b01b1fc29abff355ac00ef5c 基本概念 EGL是OpenGL ES与本地Window系统之间的桥梁.EGL创建渲染 ...
- 2527: [Poi2011]Meteors[整体二分]
2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MB Submit: 1528 Solved: 556 [Submit][S ...