【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. ...
随机推荐
- Mac osx下成功安装tensorflow
安装tensorflow有多种方式:Pip, Docker, Virtualenv, Anaconda 或 源码编译的方法安装. 我是在pip下成功安装tensorflow,以下只介绍在pip下安装( ...
- 数据库表结构导出sql语句
在“对象资源管理器”中找到要导出的表,选中该表并单击右键,“编写表脚本为(S)”/“CREATE到(C)”/“新查询编辑器窗口”即可查看该表的建表语句,Ctrl+S保存为sql脚本文件
- Python编程Web框架 :Django 从入门到精通
Django是一个高级别的Python Web框架,它鼓励快速开发和干净实用的设计. 现在我们开始学习它. Django学习之 第一章:Django介绍 Django学习之 第二章:Django快速上 ...
- 在APP开发设计过程中:如何设计启动页面?
心理学上有一个“7秒理论”,说的是,一个人对另一个人的印象,在初次见面的七秒内就会形成,最近更有研究表明,这个时间可能更短——不到1秒.所以初次见面所展示的形象真的很重要.同理,用户在使用APP时,每 ...
- NagiosQL安装
NagiosQL和Nconf是比较好用的Nagios配置工具. 一.安装NagiosQL 1.在服务器终端运行以下命令: ##YUM安装PHP模块yum -y install --disabl ...
- VTK+MFC 系列教程 非常强大
虽然QT才是王道!MFC的懂一些也是好的. 原文链接:http://blog.csdn.net/www_doling_net/article/details/8939115 之前介绍了基于VTK的单文 ...
- BZOJ 1042: [HAOI2008]硬币购物 容斥原理_背包_好题
Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买s i的价值的东西.请问每次有多少种付款方法. 题解: 十分喜 ...
- OpenVAS虚拟机安装
官方网站:http://www.openvas.org/ 参考链接:http://www.openvas.org/vm.html 下载地址:http://dl.greenbone.net/downlo ...
- Linux安装pycharm
1.pycharm包地址:链接:https://pan.baidu.com/s/1uZJDvP0DW-l7FE2J4tB-Pw 密码:5ebi rz上传到服务器 tar -zxvf pycharm-c ...
- Python编码显示中文乱码
爬虫时出现问题: import requests data=requests.get('http://roll.news.sina.com.cn/')print(data.text) 输出结果中文显示 ...