Arc076_E Connected?
题目大意
给定$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?的更多相关文章
- [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), ...
- PTA Strongly Connected Components
Write a program to find the strongly connected components in a digraph. Format of functions: void St ...
- poj 1737 Connected Graph
// poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...
- LeetCode Number of Connected Components in an Undirected Graph
原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...
- Windows Phone 8 解锁提示IpOverUsbSvc问题——IpOverUsbEnum返回No connected partners found解决方案
我的1520之前总是无法解锁,提示:IpOverUsbSvc服务没有开启什么的. 根据网上网友的各种解决方案: 1. 把手机时间设置为当前时间,并且关闭“自动设置” 2. 确保手机接入了互联网 3.确 ...
- POJ1737 Connected Graph
Connected Graph Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3156 Accepted: 1533 D ...
- [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 ...
- Supporting Connected Routes to Subnet Zero
Supporting Connected Routes to Subnet Zero IOS allows the network engineer to tell a router to eithe ...
- lintcode:Find the Connected Component in the Undirected Graph 找出无向图汇总的相连要素
题目: 找出无向图汇总的相连要素 请找出无向图中相连要素的个数. 图中的每个节点包含其邻居的 1 个标签和 1 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...
随机推荐
- Win7程序运行出现Windows Based Scrip Host 已停止工作问题的解决方法
最近在使用类似于Teamviewer这样的程序时,突然运行不了,报错:Microsoft Windows Based Scrip Host 已停止工作的问题,从系统日志来看,好像是空指针问题,但是又无 ...
- SpringMVC spring-servlet.xml配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- litou.org.cn: A Shunde Program Fan.
终于有了自己的域名litou.org.cn.(虽然并不是什么难的事) 作为顺德的一名编程爱好者,编程就是全部,希望可以多分享一些设计和开发经验. 一份耕耘,一份收获.My Name is 泥头.
- 蜗牛—ORACLE基础之触发器学习(三)
版权声明:本文为大腰子原创文章,如若转载,请标明原地址. https://blog.csdn.net/u010071361/article/details/30037215 建立一个触发器, 当职工表 ...
- java线程 同步临界区:thinking in java4 21.3.5
java线程 同步临界区:thinking in java4 21.3.5 thinking in java 4免费下载:http://download.csdn.net/detail/liangru ...
- 读取ByteBuffer有效的数据
转:https://zhidao.baidu.com/question/427134449349230532.html说道 ByteBuffer的缓冲区,就需要知道缓冲区的的三个状态1)capacit ...
- vmware 下的三种网络模式
VMWare提供三种工作模式桥接(bridge).NAT(网络地址转换)和host-only(主机模式). 桥接模式 在桥接模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机(主机和 ...
- linux 基础-变量,shell基本语法
变量 定义变量 your_name="runoob.com" #变量名和等号之间不能有空格 使用变量 your_name="qinjx" echo $your_ ...
- selenium主要功能封装
最近实习需要使用selenium这一自动化工具对公司的运维监控系统进行自动化爬取数据,编写代码过程中负责带我的杰哥让我参考借鉴他们公司外包的运维监控系统代码,在项目中我看到了对selenium主要各功 ...
- 【leetcode刷题笔记】Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...