可以发现这个问题是存在边界的,那么我们可以先放宽一下条件思考一下没有边界的情况。

通过手玩可以发现,若不存在边界总是可以完成这个任务的。

因为两条曲线之间不存在交点,那么每次我们可以从空隙穿过一条直线然后一直绕道另一端。

那么存在边界的情况特殊在一条两个点都在边界上的曲线会将整个矩形划分成两个部分,而此时若两个部分还存在点没有连接就不合法了。

但是,如果这条曲线不全是两个端点都在边界上,那么我们先将其连接对两个端点都在边界上的曲线是不会影响的,一样可以通过缝隙绕道。

那么此时只需要考虑两个端点都在边界上的曲线了。

不难发现,此时合法当且仅当不存在一条曲线将矩形分成两个区域后存在两个端点在不同区域,即不存在两条有端点连成的线段会相交。

因为每条线段都只存在于边界上,可以考虑将二维的矩形变成一维的由边界展开变成的一条线段。

那么此时原图上的线段就会变成新线段上的若干个区间。

可以发现合法的条件当且仅当这些区间只有包含和相离关系。

于是只需要从左往右扫一遍开个栈做一遍括号匹配即可。

#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 2e5 + 5;
struct node { int x, y, id;} a[N];
int n, m, h, w, x, y, xx, yy, top, st[N], book[N];
bool check(int x, int y) { return (!x || !y || (x == h) || (y == w));}
bool cmp(node a, node b) {
if(a.y == w) return (b.y < w || b.x > a.x);
if(a.x == h) return (b.y != w && (b.x < h || b.y < a.y));
if(!a.y) return (b.y != w && b.x != h && (!b.x || b.x < a.x));
if(!a.x) return (b.y != w && b.x != h && b.y && b.y > a.y);
}
int main () {
cin >> h >> w >> m;
rep(i, 1, m) {
cin >> x >> y >> xx >> yy;
if(!check(x, y) || !check(xx, yy)) continue ;
a[++n] = (node){x, y, i}, a[++n] = (node){xx, yy, i};
}
sort(a + 1, a + n + 1, cmp);
rep(i, 1, n) {
if(book[a[i].id]) {
if(a[st[top]].id != a[i].id) { puts("NO"); return 0;}
else --top;
}
else st[++top] = i, book[a[i].id] = 1;
}
puts("YES");
return 0;
}

可以发现,先放宽条件是一个当条件非常多的时候对一道题下手的一个良好方法。

其次,当某些平面 / 三维空间上只涉及边界时,可以考虑降维将边界拆成一条连续的线段然后在序列上完成这个问题。

AT2644 [ARC076C] 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. Codeforces 1076G Array Game 题解

    目录 题目大意 做法 代码 不想写昨天晚上cf的比赛题目所以来写题解摸摸鱼 题目大意 有一个在长度为\(k\)的正整数序列\(b\)上进行的游戏,一开始一个棋子放在位置\(1\),假如当前棋子的位置为 ...

  2. 团队编程二——web应用之人事管理系统

    该项目是B-S模式的web应用,以下是团队各成员的Coding链接: ------Aaric---https://coding.net/u/Aaric/p/Personnel_management_s ...

  3. 第三十三个知识点:Bellcore攻击是如何攻击使用CRT的RSA的?

    第三十三个知识点:Bellcore攻击是如何攻击使用CRT的RSA的? 注意:这篇博客是由follow论密码计算中消除错误的重要性(On the importance of Eliminating E ...

  4. Go语言练习 Rot13

    Go语言练习 Rot13 地址:https://tour.go-zh.org/methods/23 package main import ( "io" "os" ...

  5. C++函数参数的传递顺序

    C++编译器默认使用的是 __cdecl 模式,参数是通过栈传递的,因此是从右到左的传参顺序. int f(int a, int b, int c) { return 0; } int main(){ ...

  6. Java高级程序设计笔记 • 【目录】

    持续更新中- 我的大学笔记>>> 章节 内容 实践练习 Java高级程序设计作业目录(作业笔记) 第1章 Java高级程序设计笔记 • [第1章 IO流] 第2章 Java高级程序设 ...

  7. Hbase集群安装Version1.1.5

    Hbase集群安装,基于版本1.1.5, 使用hbase-1.1.5.tar.gz安装包. 1.安装说明 使用外部Zookeeper集群而非Hbase自带zookeeper, 使用Hadoop文件系统 ...

  8. PHP 的扩展类型及安装方式

    扩展类型 底层扩展(基于C语言): PECL 上层扩展(基于PHP 语言): PEAR Composer PECL # 查找扩展 $ pecl search extname # 安装扩展 $ pecl ...

  9. html基础 字符实体 用于html中特殊符号的展示 比如:多个空格、代码展示

    结构:&+英文: 常见的字符实体  

  10. 分享一款开源堡垒机-jumpserver

    本文主文章地址为:https://blog.csdn.net/KH_FC JumpServer是由FIT2CLOUD(飞致远)公司旗下一款开源的堡垒机,这款也是全球首款开源的堡垒机,使用 GNU GP ...