BZOJ 4195: [Noi2015]程序自动分析 并查集 + 离散化 + 水题
Description
在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足。
Input
输入文件的第1行包含1个正整数t,表示需要判定的问题个数。注意这些问题之间是相互独立的。
Output
输出文件包括t行。
#include<bits/stdc++.h>
#define maxn 2000002
using namespace std;
void setIO(string s)
{
string in=s+".in";
freopen(in.c_str(),"r",stdin);
}
int Arr[maxn];
struct Union
{
int p[maxn];
void init()
{
for(int i=0;i<maxn;++i) p[i]=i;
}
int find(int x)
{
return p[x]==x?x:p[x]=find(p[x]);
}
}tr;
struct OPT
{
int a,b,c;
}opt[maxn];
bool cmp(OPT a,OPT b)
{
return a.c>b.c;
}
void solve()
{
int n,tot=0,i,x,y;
scanf("%d",&n);
tr.init();
for(i=1;i<=n;++i) scanf("%d%d%d",&opt[i].a,&opt[i].b,&opt[i].c),Arr[++tot]=opt[i].a,Arr[++tot]=opt[i].b;
sort(Arr+1,Arr+1+tot);
for(i=1;i<=n;++i)
{
opt[i].a=lower_bound(Arr+1,Arr+1+tot,opt[i].a)-Arr;
opt[i].b=lower_bound(Arr+1,Arr+1+tot,opt[i].b)-Arr;
}
sort(opt+1,opt+1+n,cmp);
for(i=1;i<=n;++i)
{
switch(opt[i].c)
{
case 0 :
{
x=tr.find(opt[i].a);
y=tr.find(opt[i].b);
if(x==y)
{
printf("NO\n");
return;
}
break;
}
case 1 :
{
x=tr.find(opt[i].a);
y=tr.find(opt[i].b);
if(x!=y)tr.p[x]=y;
break;
}
}
}
printf("YES\n");
}
int main()
{
// setIO("input");
int T;
scanf("%d",&T);
while(T--) solve();
return 0;
}
BZOJ 4195: [Noi2015]程序自动分析 并查集 + 离散化 + 水题的更多相关文章
- BZOJ 4195: [Noi2015]程序自动分析 并查集+离散化
LUOGU 1955BZOJ 4195 题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3...代表程序中出现的变量 ...
- BZOJ 4195: [Noi2015]程序自动分析 [并查集 离散化 | 种类并查集WA]
题意: 给出若干相等和不等关系,判断是否可行 woc NOI考这么傻逼的题飞快打了一个种类并查集交上了然后爆零... 发现相等和不等看错了异或一下再叫woc90分 然后发现md$a \neq b, a ...
- bzoj 4195: [Noi2015]程序自动分析
4195: [Noi2015]程序自动分析 Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,…代表 ...
- BZOJ-4195 NOI2015Day1T1 程序自动分析 并查集+离散化
总的来说,这道题水的有点莫名奇妙,不过还好一次轻松A 4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 836 ...
- 【BZOJ4195】[Noi2015]程序自动分析 并查集
[BZOJ4195][Noi2015]程序自动分析 Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3 ...
- [Bzoj4195] [NOI2015] 程序自动分析 [并查集,哈希,map] 题解
用并查集+离散化,注意:并查集数组大小不是n而是n*2 #include <iostream> #include <algorithm> #include <cstdio ...
- bzoj 4195: [Noi2015]程序自动分析【并查集】
等于有传递性,所以hash一下把等于用并查集连起来,然后再判断不等于是否合法即可 #include<iostream> #include<cstdio> #include< ...
- BZOJ——4195: [Noi2015]程序自动分析
http://www.lydsy.com/JudgeOnline/problem.php?id=4195 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: ...
- [BZOJ4195] [NOI2015] 程序自动分析 (并查集)
Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,…代表程序中出现的变量,给定n个形如xi=xj或x ...
随机推荐
- round()和trunc()函数的应用
http://blog.chinaunix.net/uid-7801695-id-68136.html round()和trunc()函数的应用 关键字: round()和trunc()函数的应用 ...
- mybatis+mysql返回插入的主键,参数只是提供部分参数
mybatis+mysql返回插入的主键,参数只是提供部分参数 <insert id="insertByChannelIdOpenid" useGeneratedKeys=& ...
- 使用resultMap实现ibatis复合数据结构查询(1.多重属性查询;2.属性中含有列表查询)
以订单为例(订单详情包括了订单的基本信息,配送物流信息,商品信息),直接上代码: 1.多重属性查询 java实体 public class OrderDetail { @XmlElement(requ ...
- HBase编程实例
摘要:在前文中安装了Hbase,通过Hbase shell能够进行一些操作.可是和实际的编程实例联系起来不方便,因此本文介绍有关Hbase编程的实例. 一.使用Eclipse开发HBase应用程序 1 ...
- Test for Job (poj 3249 记忆化搜索)
Language: Default Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 9733 A ...
- 新随笔(三)什么时候使用button,什么时候使用文字链接
新随笔(三)什么时候使用button.什么时候使用文字链接 你为什么在这个地方用button而不用文字链接呢? 这是刚才我问一个设计师的问题. 她抬头看我,眼神迷茫.说:"没什么为什么呀,我 ...
- multiple web application host under the same website on IIS (authentication mode)
第一种方式,修改forms的name how to set the forms authentication cookie path assume you have already solved th ...
- hdoj--5625--Clarke and chemistry(枚举)
Clarke and chemistry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- STL 集合部分操作
3.28更新 在EOJ 1641 集合栈计算机中,使用并集和补集时候,第五个参数使用x.begin()会报错:assignment of read-only location,而使用inserter( ...
- iOS开发之KVC全解
一 KVC的基本概念 1.KVC是Key Value Coding的缩写,意思是键值编码. 在iOS中,提供了一种方法通过使用属性的名称(也就是Key)来间接访问对象属性的方法,这个方法可以不通过g ...