[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 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...
随机推荐
- node-pre-gyp以及node-gyp的源码简单解析(以安装sqlite3为例)
title: node-pre-gyp以及node-gyp的源码简单解析(以安装sqlite3为例) date: 2020-11-27 tags: node native sqlite3 前言 简单来 ...
- SpringBoot入门03-转发到Thymeleaf
前言 Spring Boot不提倡使用jsp和用View层,而是使用Thymeleaf代替jsp,因为性能可以得到提升. 使用Thymeleaf要加入依赖 Thymeleaf不能直接被访问,它严格遵守 ...
- 02Prism WPF 入门实战 - 建项
1.概要 Prism介绍 Github: https://github.com/PrismLibrary/Prism 开发文档:https://prismlibrary.com/docs/ Prism ...
- vue基本指令与脚手架基本配置
脚手架(@vue/cli)创建项目启动服务 1.创建项目 vue create 项目名字 2.启动项目 进入项目根目录,运行以下命令 yarn serve 3.脚手架目录代码分析 ├── node_m ...
- UltraSoft - Beta - Scrum Meeting 10
Date: May 26th, 2020. Scrum 情况汇报 进度情况 组员 负责 今日进度 q2l PM.后端 记录Scrum Meeting Liuzh 前端 暂无 Kkkk 前端 前端增加了 ...
- Beta阶段第二次会议
时间:2020.5.18 工作进展 姓名 工作 难度 完成度 ltx 1.在开小程序开发文档,学习相关知识 轻 85% xyq 1.完成活动场地申请可视化代码(耗时半天) 中 100% lm 1.设计 ...
- Prometheus基于Eureka的服务发现
Prometheus基于Eureka的服务发现 一.背景 二.实现步骤 1.eureka 客户端注册到prometheus中 2.prometheus中的写法 3.实现效果 三.完整代码 四.参考链接 ...
- Spring Cloud Gateway Route Predicate Factory 的使用
Spring Cloud Gateway的使用 一.需求 二.基本组成 1.简介 2.核型概念 1.Route 路由 2.Predicate 谓语.断言 3.Filter 过滤器 3.工作原理 三.网 ...
- 基于websocket实现的一个简单的聊天室
本文是基于websocket写的一个简单的聊天室的例子,可以实现简单的群聊和私聊.是基于websocket的注解方式编写的.(有一个小的缺陷,如果用户名是中文,会乱码,不知如何处理,如有人知道,请告知 ...
- HITS算法简介
1.算法名称 超文本敏感标题搜索 (Hyperlink-Induced Topic Search) 2.算法背景 HITS 算法是由康奈尔大学的Jon Kleinberg 博士于1997 年首先提出的 ...