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 ...
随机推荐
- MSXML2
The following C/C++ example creates and appends a new text node to the root document element. #impor ...
- 【ACM】hdu_zs3_1007_Rails_201308100802
Rails Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)Total Submissi ...
- springmvc 中开发Server Send Event
springmvc 中开发Server Send Event 学习了:http://blog.csdn.net/leiliz/article/details/55195203 https://www. ...
- [Angulalr] Speed Up Reducer Development Using Ngrx Schematics
When we use NGRX, we need to create some bolipates. Now with Angulalr6, we can use CLI to generate t ...
- oc37--类工厂方法
// // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject @property int ag ...
- map集合遍历的五种方法
package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...
- iOS沙盒及数据存储
时间久了容易忘,针对沙盒的相关实用技巧做一个记录和整理. 一.iOS数据存储常用方式 1.XML属性列表(plist) 不是所有对象都可以写入: 2.Preference(偏好设置) 本质还是通过“p ...
- js开发规范,在php上也适用
本篇主要介绍JS的命名规范.注释规范以及框架开发的一些问题. 目录 1. 命名规范:介绍变量.函数.常量.构造函数.类的成员等等的命名规范 2. 注释规范:介绍单行注释.多行注释以及函数注释 3. 框 ...
- c语言中struct的初始化
C++中的struct已经和class一样,可以用构造函数初始化. C语言中的struct怎么初始化呢? typedef struct _TEST_T { int i; c ...
- 虚拟机下不能运行gazebo
bug描述: VMware: vmw_ioctl_command error Invalid argument. 解决方式:设置环境变量 export SVGA_VGPU10=0 或者 echo &q ...