【POJ 1733】 Parity Game
【题目链接】
【算法】
并查集
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; struct Query
{
int l,r,op;
} q[]; int k,n,i,x,y,len;
int l[],r[],fa[],d[],a[];
char s[][]; inline int get_root(int x)
{
if (fa[x] == x) return x;
int f = get_root(fa[x]);
d[x] ^= d[fa[x]];
return fa[x] = f;
} int main()
{ scanf("%d%d",&k,&n);
for (i = ; i <= n; i++)
{
scanf("%d%d%s",&l[i],&r[i],&s[i]);
a[++len] = l[i] - ;
a[++len] = r[i];
}
sort(a+,a+len+);
len = unique(a+,a+len+) - a - ;
for (i = ; i <= n; i++)
{
q[i].l = lower_bound(a+,a+len+,l[i]-) - a;
q[i].r = lower_bound(a+,a+len+,r[i]) - a;
q[i].op = strcmp(s[i],"odd") == ? : ;
}
for (i = ; i <= * n; i++) fa[i] = i;
for (i = ; i <= n; i++)
{
x = get_root(q[i].l);
y = get_root(q[i].r);
if (x == y)
{
if ((d[q[i].l] ^ d[q[i].r]) != q[i].op)
{
printf("%d\n",i-);
exit();
}
} else
{
fa[x] = y;
d[x] = d[q[i].l] ^ d[q[i].r] ^ q[i].op;
}
}
printf("%d\n",n); return ; }
【POJ 1733】 Parity Game的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- hihoCoder挑战赛31
#1595 : Numbers 时间限制:8000ms 单点时限:1000ms 内存限制:256MB 描述 给定n个整数常数c[1], c[2], ..., c[n]和一个整数k.现在需要给2k个整数 ...
- XML 之 命名空间详解
最近学xml 遇到了点小问题qaq 找了n多的博客大佬,反复看了半小时终于明白了,可能我太蠢了... 基础的知识就不赘述,直接放“栗子”,切重点: <?xml version="1.0 ...
- new String(getBytes(ISO-8859-1),UTF-8)中文编码避免乱码
byte[] b_gbk = "深".getBytes("GBK"); byte[] b_utf8 = "深".getBytes(" ...
- re模块findall函数用法
title: Python subtitle: 1.re模块findall函数用法 date: 2018-12-13 10:17:28 --- Python re 模块 findall 函数用法简述 ...
- elasticsearch元数据
_source元数据 put /test_index/test_type/1 { "test_field1": "test field1", "tes ...
- Python笔记6----数组
1.Python 中的数组 形式: 用list和tuple等数据结构表示数组 一维数组:list=[1,2,3,4] 二维数组:list=[[1,2,3],[4,5,6],[7,8,9]] 用arra ...
- 【JavaScript框架封装】实现一个类似于JQuery的CSS样式框架的封装
// CSS 样式框架 (function (xframe) { // 需要参与链式访问的(必须使用prototype的方式来给对象扩充方法)[只要是需要使用到this获取到的元素集合这个变量的时候, ...
- 微信小程序:获取地理定位和显示相应的城市名称。
最近在看微信小程序,遇到地理定位显示城市名称的问题.本文就是记录这一过程. 解决方案 ...
- Ural 1996 Cipher Message 3 (生成函数+FFT)
题面传送门 题目大意:给你两个$01$串$a$和$b$,每$8$个字符为$1$组,每组的最后一个字符可以在$01$之间转换,求$b$成为$a$的一个子串所需的最少转换次数,以及此时是从哪开始匹配的. ...
- [网络流24题] 太空飞行计划问题 (最大流->最大权闭合图)
洛谷传送门 LOJ传送门 做这道题之前建议先看这篇论文,虽然论文里很多地方用了很多术语,但hbt神犇讲得很明白 这篇题解更加偏向于感性理解 把问题放到二分图上,左侧一列点是实验,权值为$p[i]$,右 ...