题目链接:https://vjudge.net/problem/POJ-1733

解题思路:并查集+离散化

AC代码:

 #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn=;
struct query{
int l,r;
int oe;
}q[maxn];
map<int,int> lists;
int v[maxn],fa[maxn];
int finds(int t){
if(fa[t]==-)
return t;
int tmp=finds(fa[t]);
v[t]^=v[fa[t]];
return fa[t]=tmp;
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int vals[maxn<<];
char ooe[];
int ques,len;
memset(fa,-,sizeof(fa));
memset(v,,sizeof(v));
scanf("%d",&len);
scanf("%d",&ques);
int j=;
for(int i=;i<=ques;i++){
scanf("%d%d%s",&q[i].l,&q[i].r,ooe);
q[i].l-=;
if(ooe[]=='e') q[i].oe=;
else q[i].oe=;
vals[j]=q[i].l; j++;
vals[j]=q[i].r; j++;
}
sort(vals+,vals+j);
int m=unique(vals+,vals+j)-vals-;
for(int i=;i<=m;i++){
lists[vals[i]]=i;
}
int ending=;
for(int i=;i<=ques;i++){
int t1=finds(lists[q[i].l]),t2=finds(lists[q[i].r]);
int vl=v[lists[q[i].l]],vr=v[lists[q[i].r]];
if(t1==t2){
if(vr^vl!=q[i].oe){
printf("%d\n",i-);
ending=;
break;
}
}
else{
fa[t2]=t1;
v[t2]=q[i].oe^vl^vr;
}
}
if(!ending) printf("%d\n",ques);
return ;
}

额,先这样吧,晚上或者明天再来详谈。

POJ1733的更多相关文章

  1. 【poj1733】 Parity game

    http://poj.org/problem?id=1733 (题目链接) 题意 一个由0,1组成的序列,每次给出一段区间的奇偶,问哪一条信息不合法. Solution 并查集. 题目中序列的长度有很 ...

  2. 并查集专辑 (poj1182食物链,hdu3038, poj1733, poj1984, zoj3261)

    并查集专题训练地址,注册登录了才能看到题目 并查集是一个树形的数据结构,  可以用来处理集合的问题, 也可以用来维护动态连通性,或者元素之间关系的传递(关系必须具有传递性才能有并查集来维护,因为并查集 ...

  3. POJ1733 Parity game 【扩展域并查集】*

    POJ1733 Parity game Description Now and then you play the following game with your friend. Your frie ...

  4. POJ1733 Parity game 【带权并查集】*

    POJ1733 Parity game Description Now and then you play the following game with your friend. Your frie ...

  5. 【POJ1733】Parity game

    [POJ1733]Parity game 题面 vjudge 题解 比较简单的分类并查集 将一个查询操作看作前缀和\(s_r-s_{l-1}\)的奇偶性 将每个点拆成一奇一偶然后分别连边即可 如果一个 ...

  6. poj1733(种类并查集+离散化)

    题目链接: http://poj.org/problem?id=1733 题意: 输入n表示有一个长度为n的0,1字符串, m表示接下来有m行输入, 接下来的m行输入中x, y, even表示第x到第 ...

  7. poj1733 带权并查集

    题意:有一个 0/1 数列,现在有n组询问和回答,表示某个区间内有奇数或者偶数个1,问到前多少个都没有逻辑错误,而下一个就不满足 可以定奇数为 1 偶数为 0作为每个元素的权值,表示它与它的祖先元素的 ...

  8. 【POJ1733】【带标记并查集】Parity game

    Description Now and then you play the following game with your friend. Your friend writes down a seq ...

  9. poj1733(并查集+离散化)

    题目大意:有一个长度为n的0,1字符串, 给m条信息,每条信息表示第x到第y个字符中间1的个数为偶数个或奇数个, 若这些信息中第k+1是第一次与前面的话矛盾, 输出k; 思路:x, y之间1的个数为偶 ...

随机推荐

  1. Gym 101194F Mr. Panda and Fantastic Beasts

    #include<bits/stdc++.h> using namespace std; #define ms(arr,a) memset(arr,a,sizeof arr) #defin ...

  2. nginx开启ssl并把http重定向到https的两种方式

    1 简介 Nginx是一个非常强大和流行的高性能Web服务器.本文讲解Nginx如何整合https并将http重定向到https. https相关文章如下: (1)Springboot整合https原 ...

  3. Spring PropertyPlaceholderConfigurer类载入外部配置

    2019独角兽企业重金招聘Python工程师标准>>> 通常在Spring项目中如果用到配置文件时,常常会使用org.springframework.beans.factory.co ...

  4. 数学--数论--HDU--5878 Count Two Three 2016 ACM/ICPC Asia Regional Qingdao Online 1001

    I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started ...

  5. 疯子的算法总结(六) 复杂排序算法 ① 归并排序 merge_sort()

    归并排序采取了分治的思想,每次分别排左半边和右半边,不断递归调用自己,直到只有一个元素递归结束,开始回溯,调用merge函数,合并两个有序序列,再合并的时候每次给末尾追上一个最大int这样就不怕最后一 ...

  6. 图论--传递闭包(Floyd模板)

    #include<iostream> #include<cstring> #include<cmath> using namespace std; int dp[1 ...

  7. UVA-2【NOI2014】起床困难综合症

    #2. [NOI2014]起床困难综合症 21 世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm 一直坚持与起床困难综合症作斗争.通过 ...

  8. python(读取 excel 操作 xlrd 模块)

    一.安装 xlrd 模块 到 python 官网下载 http://pypi.python.org/pypi/xlrd 模块安装,前提是已经安装了 python 环境. 或者在 cmd 窗口  pip ...

  9. web安全笔记

    判断网站是否伪静态 把.html后缀即可或者加.php?id=99 例子:33_99.html   去掉.html和_变成33.php?id=99 即可判断是否伪静态 判断网站是否在win或者linu ...

  10. LeetCode 98. 验证二叉搜索树 | Python

    98. 验证二叉搜索树 题目来源:https://leetcode-cn.com/problems/validate-binary-search-tree 题目 给定一个二叉树,判断其是否是一个有效的 ...