题目链接: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. 《Java 开发从入门到精通》—— 2.3 使用IDE工具序

    本节书摘来异步社区<Java 开发从入门到精通>一书中的第2章,第2.3节,作者: 扶松柏 , 陈小玉,更多章节内容可以访问云栖社区"异步社区"公众号查看. 2.3 使 ...

  2. Intellij-IDEA-maven+springMVC+mybatis整合

    2019独角兽企业重金招聘Python工程师标准>>> GitHub地址 https://github.com/Ethel731/WebProjectDemo 前言 之前都是在已经建 ...

  3. Docker学习之搭建MySql容器服务

    描述 MySQL 5.6 SQL数据库服务器Docker镜像,此容器映像包含用于OpenShift的MySQL 5.6 SQL数据库服务器和一般用法.用户可以选择RHEL和基于CentOS的图像.然后 ...

  4. 使用PHP-Beast加密你的PHP源代码

    PHP-Beast是一个PHP源码加密的模块,其使用DES算法加密,用户可以自定义加密的key来加密源代码. 1. PHP-Beast的安装 $ wget https://github.com/lie ...

  5. C++课程设计详解-12306的模拟实现

    目录 设计思路... 3 思路分析:.... 3 数据组织:.... 4 具体功能实现过程... 4 管理端具体功能实现:.... 4 用户端具体功能实现:.... 5 调试截图和调试过程中遇到的问题 ...

  6. CF思维联系–CodeForces - 225C. Barcode(二路动态规划)

    ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...

  7. 刷新DNS解析缓存+追踪+域名解析命令

    刷新DNS解析缓存 命令:ipconfig /flushdns 用于改完host之后. 追踪IP: 命令:tracert www.baidu.com 域名解析: 命令:nslookup www.bai ...

  8. ST函数(ST表)RMQ O(1)查询 离线

    ST算法是基于倍增的动态规划算法. #include<iostream> #include<cstdio> #include<cstdlib> #include&l ...

  9. TensorRT入门

    本文转载于:子棐之GPGPU 的 TensorRT系列入门篇 学习一下加深印象 Why TensorRT 训练对于深度学习来说是为了获得一个性能优异的模型,其主要的关注点在与模型的准确度.精度等指标. ...

  10. 聊聊select, poll 和 epoll

    聊聊select, poll 和 epoll 假设项目上需要实现一个TCP的客户端和服务器从而进行跨机器的数据收发,我们很可能翻阅一些资料,然后写出如下的代码. 服务端 void func(int s ...