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 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...
随机推荐
- CentOS升级Python2.6到Python2.7
个人博客:https://blog.sharedata.info/ 貌似CentOS 6.X系统默认安装的Python都是2.6版本的?平时使用以及很多的库都是要求用到2.7版本或以上,所以新系统要做 ...
- [T-SQL] 获取拼音
)) ) as begin ) ) declare @i int declare @words_len int declare @unicode int set @words = ltrim(rtri ...
- PAT 1065. 单身狗(25)
“单身狗”是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数:随后N行 ...
- require.js vs browserify
require.js vs browserify require.js是模块加载器:browserify是预编译工具 require.js遵循的是AMD规范:browserify遵循的是CommonJ ...
- SAP号码段
[转http://blog.csdn.net/wengyupeng/article/details/8513527] 1.通用Tcode:SNRO 常用维护特定Number range Tcode: ...
- c语言操作mysql数据库
c语言操作Mysql数据库,主要就是为了实现对数据库的增.删.改.查等操作,操作之前,得先连接数据库啊,而连接数据库主要有两种方法.一.使用mysql本身提供的API,在mysql的安装目录中可可以看 ...
- Iptalbes练习题(三)
场景需求: (1)员工在公司内部(192.168.124.0/24 ,192.168.122.0/24 )能访问服务器上任何服务 (2)当员工出差,通过VPN连接到公司 (3)公司门户网站允许公网访问 ...
- 阿里云修改centos7主机名
为了玩Docker,买个阿里云主机也是够拼的了. [root@iZ284olvkmjZ ~]# 不过主机名中怎么好DT,无奈,修改. 我们需要的是永久生效,阿里云提供了两种方法: 方法(1). 输入h ...
- LeetCode:验证回文串【125】
LeetCode:验证回文串[125] 题目描述 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: ...
- 基于Web的实验室管理系统技术简要报告
基于Web的实验室管理系统技术简要报告 Copyright 朱向洋 Sunsea ALL Right Reserved 一.网站架构 该网站使用C#语言,利用SQL Server2008数据库,采用V ...