传送门

题目大意

给定$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. jquery实现全选、全消、反选功能

    HTML代码: <input type="checkbox" name="checkbox" class="A" /> 使用按钮 ...

  2. yii2.0 中的队列

    a yii2 extension to make simple to use queue. yii2-queue让队列的使用在yii2中变得更轻松,她为各种队列组件的使用提供了一个标准的接口,您只需要 ...

  3. spring bean的scope

    scope用来声明容器中的对象所应该处的限定场景或者说该对象的存活时间,即容器在对象进入其相应的scope之前,生成并装配这些对象,在该对象不再处于这些scope的限定之后,容器通常会销毁这些对象. ...

  4. SET IDENTITY_INSERT ON/OFF 权限

    今天突然遇到了,找不到对象“XXXX”,因为它不存在或者没有您所需的权限,于是检查程序,突然发现程序中有一段代码是: SET IDENTITY_INSERT eticket ON //执行业务 ... ...

  5. 3.设计模式----TemplateMethod模式

    模板模式,其实是一种思想,在开发中有很多地方用到模板,因为毕竟我们不可能每一个都一出一段!一个模板,填充不同,出来效果也是不一样! 准备画个时序图的,没找到工具,过几天补上! 模板模式在出现bug时候 ...

  6. 【python】-- 继承式多线程、守护线程

    继承式多线程 1.定义 继承式多线程是自己自定义类,去继承theading.Tread这个类,通过类实例.start()启动,去执行run方法中的代码. import threading import ...

  7. 【python】-- web开发之HTML

    HTML HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,是一种制作万维网页面标准语言(标记).通俗的讲就是相当于定义统一的一套规则,大家都来遵守他,这样 ...

  8. [note]可持久化Trie

    可持久化Trie 参考可持久化线段树的思想,修改的时候先直接复制,再对需要修改的点新建节点 可持久化Trie也是同样的做法,假设现在需要在原本Trie的基础上插入一个字符串 先把上个Trie的对应节点 ...

  9. Python过滤

    text = "A2A"s = filter(lambda ch: ch in '0123456789', text)print int(s)

  10. matlab 代码加速

    ~ 使用 parfor 代替 for 1. 安装 Parallel Computing Toolbox, 使用 parfor代替for, 使用的是cpu多核,速度能提高三倍左右. ~ 在for循环中的 ...