[atARC076E]Connected
首先,如果没有这个平面的限制,考虑不断插入一对点,将与这两点连线有交的线从左到右,依次“移动”到左端点边上,因此一定是可行的
但当存在界限后,对于两个端点都在边界上的点对(一个端点在边界上还是可以用同样的构造),需要判断是否存在合法解:
如果将整个边界看作一个环,若存在两个点对$i$和$j$满足以$ijij$的顺序,那么一定不合法
同时,若不存在这样的关系,通过上述构造,先练两个端点不都在边界上的点对,再连都在边界上的点对,一定可行
考虑如何判定,由于这样的点对从任意一个点开始都是这样的形式,因此从某一点出发,维护一个栈表示当前还没有匹配的点,若当前点已经被插入栈中,且不为栈顶则无解,否则删除栈顶即可

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 100005
4 #define y1 y11
5 vector<int>v;
6 vector<pair<int,int> >vv[4];
7 stack<int>st;
8 int r,c,n,x1,y1,x2,y2,vis[N];
9 bool pd(int x,int y){
10 return ((!x)||(y==c)||(x==r)||(!y));
11 }
12 void push(int x,int y,int k){
13 if (!x)vv[0].push_back(make_pair(y,k));
14 else{
15 if (y==c)vv[1].push_back(make_pair(x,k));
16 else{
17 if (x==r)vv[2].push_back(make_pair(y,k));
18 else{
19 if (!y)vv[3].push_back(make_pair(x,k));
20 }
21 }
22 }
23 }
24 int main(){
25 scanf("%d%d%d",&r,&c,&n);
26 for(int i=1;i<=n;i++){
27 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
28 if ((pd(x1,y1))&&(pd(x2,y2))){
29 push(x1,y1,i);
30 push(x2,y2,i);
31 }
32 }
33 for(int i=0;i<4;i++)sort(vv[i].begin(),vv[i].end());
34 for(int i=0;i<4;i++)
35 if (i<2)
36 for(int j=0;j<vv[i].size();j++)v.push_back(vv[i][j].second);
37 else
38 for(int j=vv[i].size()-1;j>=0;j--)v.push_back(vv[i][j].second);
39 for(int i=0;i<v.size();i++)
40 if (!vis[v[i]]){
41 vis[v[i]]=1;
42 st.push(v[i]);
43 }
44 else{
45 if (st.top()!=v[i]){
46 printf("NO");
47 return 0;
48 }
49 st.pop();
50 }
51 printf("YES");
52 }
[atARC076E]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 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...
随机推荐
- SpringBoot入门06-Thymeleaf显示作用域对象种的对象
作用域对象request,session, servletContext中的数据在Thymeleaf中的显示都是相同的 作用域对象中的 List和Set的集合在html中的显示是相同的 作用域对象中的 ...
- Probius+Prometheus通过API集成POD监控
上一篇文章Probius+Kubernetes任务系统如虎添翼讲了我们把Kubernetes集成进了任务系统Probius,上线后小伙伴反馈虽然摆脱了Kubernetes-Dashboard,但还是得 ...
- Ubuntu安装 配置GCC和Vim
VMware14.0和Ubuntu镜像安装 https://mp.weixin.qq.com/s/045wrbdv92PkUQn2abddvA 适应屏幕设置 按照下列流程检查虚拟机设置 查看 -> ...
- ByteCTF2021 double sqli
double sqli easy sqli http://39.105.175.150:30001/?id=1 http://39.105.116.246:30001/?id=1 http://39. ...
- Python 做简单的登录系统
案例 之 登录系统原创作品1 该随笔 仅插入部分代码:全部py文件源代码请从百度网盘自行下载! 链接:https://pan.baidu.com/s/1_sTcDvs5XEGDcnpoQEIrMg 提 ...
- js_数据类型转换
转整数----parseInt(string,radix) 1)类似于从左往右匹配数字,直到匹配到非数字结束,并返回匹配到的数字.同parseFloat(). parseInt("123&q ...
- Noip模拟16 2021.7.15
题目真是越来越变态了 T1 Star Way To Heaven 首先,你要看出这是一个最小生成树的题(妙吧?) 为什么可以呢? 我们发现从两点连线的中点过是最优的,但是上下边界怎么办呢? 我们把上下 ...
- qgis3.16.6+vs2017再编译(debug+release)
参考 https://www.cnblogs.com/superbi/p/11188145.html 文章以及其它文章,对qggis3.16.6进行了重新编译 一.编译准备 1.Cygwin 1.1安 ...
- hdu 2860 Regroup(并查集)
题意: AP x yA recruit with ability rate x were asked to join company y. (0<=x<2^31, 0<=y<n ...
- cf18B Platforms(仔细谨慎题)
题意: In one one-dimensional world there are n platforms. Platform with index k (platforms are numbere ...