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 ...
随机推荐
- Window日志分析
0X00 简介 0x01 基本设置 A.Windows审核策略设置 前提:开启审核策略,若日后系统出现故障.安全事故则可以查看系统的日志文件,排除故障,追查入侵者的信息等. 打开设置窗口 Window ...
- Explaining Delegates in C# - Part 2 (Events 1)
In my previous post, I spoke about a few very basic and simple reasons of using delegates - primaril ...
- Redis 操作集合数据
Redis 操作集合数据: > sadd set1 Tom // sadd 用于往集合中添加元素 (integer) > sadd set1 John (integer) > sad ...
- 原创:超简单!windows配置NDK开发环境使用JNI
前段时间看android版的opencv的配置教程时,看到了它的NDK配置方法,感觉简单又不会出错!!! 1.下载NDK,设置NDK路径: 在windows的系统环境变量中添加NDK的路径,环境变量名 ...
- JS 省市县三级联动
$(".area").change(function(ent,arg){ var $this = $(this), level = $(this).attr("id&qu ...
- 微信JSSDK支付接口-安卓机无法正常调起接口
今天碰到个问题,是项目调起微信支付接口,苹果机都没有什么问题,但是安卓机的情况就是支付接口出现一下就消失了 试了将error反馈信息弹出来,也就是显示choosewxpay fail 找了半天不知道什 ...
- 【Mac】WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
使用Mac 自带终端 链接服务器时候,报错如下 处理办法: 第一种: 直接删除: /users/username/.ssh/known_hosts 文件 第二种: ssh-keygen -R ...
- RH318之域控服务器
Windows2012域控服务器 一.安装域服务及DNS 1.配置静态IP 2.点击左下角 3.进入--->服务器管理器 4.点击角色和功能 勾选Active Directory域服务与DNS服 ...
- python tkinter Listbox用法
python tkinter组件的Listbox的用法,见下面代码的演示: from tkinter import * root=Tk() v=StringVar() #Listbox与变量绑定' l ...
- GTID与MHA
MHA 基于binlog文件位置的复制 * Phase 3: Master Recovery Phase.. * Phase 3.1: Getting Latest Slaves Phase.. La ...