【BZOJ4195】 [Noi2015]程序自动分析
Description
在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足。
Input
输入文件的第1行包含1个正整数t,表示需要判定的问题个数。注意这些问题之间是相互独立的。
Output
输出文件包括t行。
Sample Input
2
1 2 1
1 2 0
2
1 2 1
2 1 1
Sample Output
YES
HINT
在第一个问题中,约束条件为:x1=x2,x1≠x2。这两个约束条件互相矛盾,因此不可被同时满足。
Solution
离散化完并查集。
Code
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif #define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[ << ], *_S = _B, *_T = _B;
inline int F()
{
R char ch; R int cnt = ; R bool minus = ;
while (ch = getc(), (ch < '' || ch > '') && ch != '-') ;
ch == '-' ? minus = : cnt = ch - '';
while (ch = getc(), ch >= '' && ch <= '') cnt = cnt * + ch - '';
return minus ? -cnt : cnt;
}
#define maxn 1000010
struct Query
{
int a, b, type;
inline bool operator < (const Query &that) const {return type > that.type;}
}q[maxn];
int hash[maxn << ], Fa[maxn << ];
int Find(R int x) {return Fa[x] == x ? x : Fa[x] = Find(Fa[x]);}
int main()
{
// setfile();
for (R int cas = , t = F(); cas <= t; ++cas)
{
R int n = F(), hashcnt = ;
for (R int i = ; i <= n; ++i)
{
q[i] = (Query) {F(), F(), F()};
hash[++hashcnt] = q[i].a;
hash[++hashcnt] = q[i].b;
}
std::sort(hash + , hash + hashcnt + );
std::sort(q + , q + n + );
hashcnt = std::unique(hash + , hash + hashcnt + ) - hash - ;
for (R int i = ; i <= (hashcnt << ); ++i) Fa[i] = i;
R bool flag = ;
for (R int i = ; i <= n; ++i)
{
q[i].a = std::lower_bound(hash + , hash + hashcnt + , q[i].a) - hash;
q[i].b = std::lower_bound(hash + , hash + hashcnt + , q[i].b) - hash;
// printf("i = %d %d %d %d\n", i, q[i].a, q[i].b, q[i].type );
R int f1 = Find(q[i].a), f2 = Find(q[i].a + hashcnt);
R int f3 = Find(q[i].b), f4 = Find(q[i].b + hashcnt);
if (q[i].type == )
{
if (f1 == f3 || f2 == f4)
{
puts("NO");
flag = ;
break;
}
}
else
{
if (f1 == f3 || f2 == f4) continue;
Fa[f1] = f3;
Fa[f2] = f4;
}
}
flag ? puts("YES") : ;
}
return ;
}
/*
1
9
24 234 1
2837 1 1
242 78 0
23 1 1
223 977 0
254 76 1
235 877 0
235 987 0
877 987 0
*/
【BZOJ4195】 [Noi2015]程序自动分析的更多相关文章
- [UOJ#127][BZOJ4195][NOI2015]程序自动分析
[UOJ#127][BZOJ4195][NOI2015]程序自动分析 试题描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2, ...
- BZOJ4195 [Noi2015]程序自动分析(离散化+并查集)
4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 689 Solved: 296 [Submit][Sta ...
- BZOJ4195 NOI2015 程序自动分析
4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Description 在实现程序自动分析的过程中,常常需要判定一些约束条件 ...
- [BZOJ4195] [NOI2015] 程序自动分析 (并查集)
Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,…代表程序中出现的变量,给定n个形如xi=xj或x ...
- bzoj4195 [Noi2015]程序自动分析——并查集
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4195 突然在这道大水题上WA了半天... 思路很简单,离线处理询问,先把 = 的都加到并查集 ...
- [Bzoj4195] [NOI2015] 程序自动分析 [并查集,哈希,map] 题解
用并查集+离散化,注意:并查集数组大小不是n而是n*2 #include <iostream> #include <algorithm> #include <cstdio ...
- 【BZOJ4195】[Noi2015]程序自动分析 并查集
[BZOJ4195][Noi2015]程序自动分析 Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3 ...
- BZOJ-4195 NOI2015Day1T1 程序自动分析 并查集+离散化
总的来说,这道题水的有点莫名奇妙,不过还好一次轻松A 4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 836 ...
- codevs4600 [NOI2015]程序自动分析==洛谷P1955 程序自动分析
4600 [NOI2015]程序自动分析 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 在实现 ...
- Codevs 4600 [NOI2015]程序自动分析
4600 [NOI2015]程序自动分析 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 在实现程序自动分析的过程中,常常需 ...
随机推荐
- HDU 1753 大明A+B (大正小数加法、字符串处理)
大明A+B Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- [转帖] 国产x86-海光禅定 2018年营收过亿?
中科曙光:全年业绩稳健,海光芯片营收过亿 X86服务器市场Intel占据绝对优势:X86处理器已经成为全球最广泛使用的处理器架构之一,尤其是在PC和服务器领域,其中在处理器市场的份额高达90%以上.中 ...
- Zookeeper群起脚本启动失败及查看状态出现:Error contacting service. It is probably not running
1.问题: 群起脚本启动后查看jps没有出现:QuorumPeerMain Zookeeper正常启动但是群起脚本查状态出现:Error contacting service. It is proba ...
- MyEclipse 2013 破解
本文链接:https://blog.csdn.net/Jayliue/article/details/97414181 1.运行cracker.jar 用 cd 命令找到 cracker.jar所在目 ...
- 一道最大公约数的题:easy number
现有n个Zack,每个Zack有一个一个能力值,从这n个Zack中选出k个,使他们的最大公约数的值最大 [输入格式] 第一行有一个整数n,代表有n个Zack 第二行n个整数ai,代表每个Zack的能力 ...
- Luogu P4602 [CTSC2018]混合果汁
题目 把果汁按美味度降序排序,以单价为下标插入主席树,记录每个节点的\(sum\)果汁升数和\(val\)果汁总价. 每次询问二分最小美味度,查询美味度大于等于\(mid\)的总体积为\(L\)的最低 ...
- 在linux下和Mac下如何实现快捷方式连接SSH远程服务器
其实特别简单 在本地命令执行目录/usr/local/bin 下新建一个shell脚本 比如 #vim ssh1 写入要执行的内容连接SSH #!/usr/bin/expect -f set user ...
- php中use关键词使用场景
php中use关键词使用场景,主要使用在函数内部使用外包得变量才使用得 1,这种函数使用不到外包变量 $messge="96net.com.cn"; $exam=function ...
- python 抓取拉勾网 攻略
废话不多说,直接上代码,将数据存入Mongdb import requests import pymongo import time import random mycon = pymongo.Mon ...
- AQtime使用
今天刚到网上下了AQtime.因为有个通信及数据存储的程序出现的内存泄漏.在用户的环境里出现了两次,在测试的环境里一次也没有出现,开发人员猜测是一部分代码引起的.说要代码的覆盖测试.看看测试环境里有那 ...