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 ...
随机推荐
- iOS开发-- 使用VVDocumenter-Xcode添加代码注释
在开发Java代码过程中,我们只需在Eclipse中敲/**即可生成字段.方法对应的文档,简单便捷. 在Xcode如果想添加文档注释,需要花费很多时间,有没有简单.快速的方法搞定这一切? 在网上搜索了 ...
- iOS开发--UILabel可以显示\n
UILabel*label; //设置换行 label.lineBreakMode = UILineBreakModeWordWrap; label.numberOfLines = ; 换行符还是“\ ...
- Selenium 异常处理
在使用 Selenium 的过程中,难免会遇到一些异常,例如超时.节点未找到等错误,我们可以使用 try...except... 语句来捕获各种异常 更多异常类参考官网:https://seleniu ...
- sine曲线向前运动
using UnityEngine; using System.Collections; public class sineWork : MonoBehaviour { float verticalS ...
- windows 命令行下 简单好用的查看端口占用情况的方法
在windows命令行窗口下执行: C:\>netstat -aon|findstr "4444" TCP 127.0.0.1:4444 0.0.0.0:0 LISTENIN ...
- 【Phalapi2.0】 如何使用 source 通过 header 传参数
做接口服务时候.有些场景会使用header 来传递参数. 查看官网文档说明 数据来源 source指定当前单个参数的数据来源,可以是post.get.cookie.server.request.hea ...
- 【前端系列】移动前端开发之viewport的深入理解
在页面上没有设置width所以样式显示有问题,本来选择的响应式模式的320*410结果看到页面的实际宽度确实980px. 本文转载自: 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的 ...
- js 判断数组重复元素以及重复的个数
知识点: .sort()方法用于对数组元素排序,并返回数组. var _arr = ['旅行箱', '旅行箱', '小米', '大米']; var _res = []; // _arr.sort(); ...
- 如何使用Gradle的maven-publish将jar包或者war包上传到nexus仓库
首先,在build.gradle里边声明依赖maven-publish插件: apply plugin: 'maven-publish' 然后,配置项目的信息和和nexus的信息: publishin ...
- 【咸鱼教程】基于系统时间的计时器DateTimer(不受FPS影响)
教程目录一 计时器简介二 计时器实现三 Demo下载 一 计时器简介在手机上跑游戏时,可能由于运动物体过多,导致帧频太低,计时不准确.比如一些倒计时的游戏,可能倒计时30s,变成了35s.比如ipho ...