传送门

题目大意

给定$H\times W$的网格$(W,H\leq 10^8)$上的$N$对顶点,即两线交叉的交叉点而非格子内部$(N\leq 10^5)$,求是否存在至少一种方案使得每对点之间都有一条不出网格边界的曲线且曲线互不相交。

题解

假设当前连线情况确定,两点之间是否存在意在连线的可能仅与两点间的连通性由有关,很显然当一对点有任意一点不在边界上,那么由于所有点两两不同,那么连接这对点对其他点对的连通性毫无影响,所以我们只需要判断所有点都在边界上的那些点对之间有没有两两交叉的即可。

可以将方格边界上顺时针标号,将每个对点看做一个区间,判断区间之间是否只存在包含关系即可,这个用类似括号序列一样的方法用栈维护递增的左端点,最后只需要判断栈中有没有未删掉的元素。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 400020
using namespace std;
int read(){
int nm=0,fh=1; int cw=getchar();
for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
return nm*fh;
}
struct num{
int pos,id;num(){pos=0,id=0;}
num(int _pos,int _id){pos=_pos,id=_id;}
}p[M],S[M];
int vis[M],H,W,n,top;
bool on(int x,int y){return x==0||y==0||x==H||y==W;}
int bas(int x,int y){
if(!x) return y; if(y==W) return W+x;
if(x==H) return W+H+W-y; return W+H+W+H-x;
}
bool cmp(num x,num y){return x.pos<y.pos;}
int main(){
H=read(),W=read(),n=read();
for(int i=1;i<=n;i++){
int x=read(),y=read(),xx=read(),yy=read();
if(!on(x,y)||!on(xx,yy)){i--,n--;continue;}
int L=bas(x,y),R=bas(xx,yy); if(L>R) swap(L,R);
p[(i<<1)-1]=num(L,i),p[i<<1]=num(R,i);
} n<<=1,sort(p+1,p+n+1,cmp);
for(int i=1;i<=n;i++){if(S[top].id!=p[i].id||!top) top++,S[top]=p[i];else top--;}
puts(top?"NO":"YES"); return 0;
}

Arc076_E Connected?的更多相关文章

  1. [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  2. PTA Strongly Connected Components

    Write a program to find the strongly connected components in a digraph. Format of functions: void St ...

  3. poj 1737 Connected Graph

    // poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...

  4. LeetCode Number of Connected Components in an Undirected Graph

    原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...

  5. Windows Phone 8 解锁提示IpOverUsbSvc问题——IpOverUsbEnum返回No connected partners found解决方案

    我的1520之前总是无法解锁,提示:IpOverUsbSvc服务没有开启什么的. 根据网上网友的各种解决方案: 1. 把手机时间设置为当前时间,并且关闭“自动设置” 2. 确保手机接入了互联网 3.确 ...

  6. POJ1737 Connected Graph

    Connected Graph Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3156   Accepted: 1533 D ...

  7. [LintCode] Find the Weak Connected Component in the Directed Graph

      Find the number Weak Connected Component in the directed graph. Each node in the graph contains a ...

  8. Supporting Connected Routes to Subnet Zero

    Supporting Connected Routes to Subnet Zero IOS allows the network engineer to tell a router to eithe ...

  9. lintcode:Find the Connected Component in the Undirected Graph 找出无向图汇总的相连要素

    题目: 找出无向图汇总的相连要素 请找出无向图中相连要素的个数. 图中的每个节点包含其邻居的 1 个标签和 1 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...

随机推荐

  1. table中tr的display属性在火狐中显示不正常,IE中显示正常

    最近在作项目的时候碰到一个问题,就是需要AJAX来交互显示<tr> </tr> 标签内的东西,按照常理,对于某一单元行需要显示时,使用:display:block属性,不需要显 ...

  2. 大数据学习系列(6)-- zookeeper集群搭建

    下载 wget http://mirrors.shuosc.org/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz tar -zxvf ...

  3. Maven插件wro4j-maven-plugin压缩、合并js、css详解

    1.    在pom.xml文件中,引入wro4j-maven-plugin插件 <plugin> <groupId>ro.isdc.wro4j</groupId> ...

  4. Spring @Configuration注解

    1 该注解的用途 这个注解表示这个类可以作为spring ioc容器bean的来源,其本质上它是对xml文件中创建bean的一种替换.有了这个注释,Spring framework就能在需要的时候构造 ...

  5. 我的Android进阶之旅------>Android中android:windowSoftInputMode的用法

    面试题:如何在显示某个Activity时立即弹出软键盘? 答案:在AndroidManifest.xml文件中设置<activity>标签的android:windowSoftInputM ...

  6. spark 在yarn执行job时一直抱0.0.0.0:8030错误

    近日新写完的spark任务放到yarn上面执行时,在yarn的slave节点中一直看到报错日志:连接不到0.0.0.0:8030 . The logs are as below: 2014-08-11 ...

  7. GIT笔记:GITHUB教程【官方自译版】

    GIT笔记:将项目发布到GITHUB GITHUB是什么 GitHub是版本控制和协作的代码托管平台.它可以让你和其他人在任何地方一起工作. 1.创建一个新的仓库 存储库通常用于组织单个项目.存储库可 ...

  8. struts2核心和工作原理

    转至:http://blog.csdn.net/laner0515/article/details/27692673 在学习struts2之前,首先我们要明白使用struts2的目的是什么?它能给我们 ...

  9. 小程序坑 redirectTo 计时器 setInterval clearInterval

    var time = 20: var timer = setInterval(function () { time = time - 1; that.setData({ CountDown: time ...

  10. ie6不认识

    1.   ie6 不认识这样连续写的类选择 .class1.class2{  } 2.   ie6 下不解析 css  input[type="text"] 等等类别的选择