大意: 给定$n$个平面上互不相交的矩形. 若一个矩形区域只包含一个矩形或者它可以水平或垂直切成两块好的区域, 那么这个矩形区域是好的. 求判断整个平面区域是否是好的.

分治判断, 可以用链表实现删除元素, 或者直接用$set$

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//headconst int N = 1e6+10;
struct _ {int l,r,id;bool operator < (const _ &rhs) const {if (l==rhs.l) return id<rhs.id;return l<rhs.l;}
} a[N][4];
set<_> s[4];int dfs(set<_> L[4]) {if (L[0].size()<=1) return 1;set<_> R[4];set<_>::iterator it[4];int m[4];REP(i,0,3) {it[i] = L[i].begin();m[i] = it[i]++->r;}int sz = L[0].size();REP(i,1,sz-1) REP(j,0,3) {if (it[j]->l>=m[j]) {for (auto t=L[j].begin(); t!=it[j]; ) {int id = t++->id;REP(k,0,3) R[k].insert(a[id][k]),L[k].erase(a[id][k]);}return dfs(L)&&dfs(R);}m[j] = max(m[j], it[j]++->r);}return 0;
}int main() {int n=rd();REP(i,1,n) {int x1=rd(),y1=rd(),x2=rd(),y2=rd();a[i][0] = {x1,x2,i};a[i][1] = {-x2,-x1,i};a[i][2] = {y1,y2,i};a[i][3] = {-y2,-y1,i};REP(j,0,3) s[j].insert(a[i][j]);}cout<<(dfs(s)?"YES":"NO")<<endl;
}

转载于:https://www.cnblogs.com/uid001/p/11308341.html

A Story of One Country (Hard) CodeForces - 1181E2 (分治)相关推荐

  1. Codeforces 894.D Ralph And His Tour in Binary Country

    D. Ralph And His Tour in Binary Country time limit per test 2.5 seconds memory limit per test 512 me ...

  2. 【Codeforces】Round #375 (Div. 2)

    Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...

  3. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  4. Codeforces 543 B. World Tour

    http://codeforces.com/problemset/problem/543/B 题意: 给定一张边权均为1的无向图. 问至多可以删除多少边,使得s1到t1的最短路不超过l1,s2到t2的 ...

  5. Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca

    B. Bribes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/B De ...

  6. Codeforces 544D Destroying Roads

    链接:http://codeforces.com/problemset/problem/543/B B. Destroying Roads time limit per test:2 seconds ...

  7. codeforces 1181C

    原题http://codeforces.com/problemset/problem/1181/C C. Flag time limit per test 2 seconds memory limit ...

  8. cf Educational Codeforces Round 85 (Rated for Div. 2)B. Middle Class

    题目链接:https://codeforces.com/contest/1334/problem/B B. Middle Class time limit per test2 seconds memo ...

  9. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  10. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

最新文章

  1. escape php解码,PHP对escape的字符串进行解密 、加密 | 学步园
  2. 查找 framework 文件中是否包含 WKWebView
  3. Android定位开发之百度定位、高德定位、腾讯定位,三足鼎立一起为我所用!
  4. Solr 5.4.0
  5. Cloud一分钟 | Gartner发布2018年第二季度全球服务器市场报告;中信银行联合腾讯云推出手机银行智能语音产品...
  6. Red Hat Enterprise Linux (RHEL) 6.4 DVD ISO 迅雷下载地址
  7. 解决 Error L6915E 问题
  8. 机器学习实战(二)决策树DT(Decision Tree、ID3算法)
  9. Web报表页面如何传递中文参数
  10. NUC1474 Ants【水题】
  11. sql collection内容_非关系数据库复习|SQL到mongoDB查询语句转换
  12. 如何进入Dos窗口以及了解常用Dos命令
  13. macd的VB计算机程序,大智慧自选股实时同步到通达信VB小软件简单升级
  14. 计算机系统怎么装到u盘启动不了,电脑开机就进入BIOS界面,设置了u盘启动准备从装系统但是进不了U盘,这些是为什么啊?...
  15. 模态框中弹模态框的问题
  16. 字谜 大小写重复全排列问题
  17. HTML5特效(shadow、gradient、transition、transform、filter)
  18. 项羽ol网站服务器,《项羽ol》4千万平米无缝地图带你飞
  19. java+小时转为分钟_用java将12862秒转换成 N 小时,K 分钟,M 秒
  20. kube-apiserver准入

热门文章

  1. android荧光进度条,Android ProgressBar 进度条荧光效果
  2. php如何隐藏入口文件,php怎么隐藏入口文件
  3. java 正则表达式大全_Java 正则表达式大全
  4. 计算机音乐tfboys手机,TFBoys王源的iPhone挂了 别怕 手贱有得治
  5. sleuth zipkin mysql_springCloud的使用08-----服务链路追踪(sleuth+zipkin)
  6. python turtle原点位置_python中turtle库中setworldcoordinates(坐标系的移动)
  7. matlab调用python数值精度改变吗_Matlab如何调用python脚本-matlab调用python数值精度改变吗 - PS下...
  8. 616nyoj 新手dp
  9. HDU 2545 树上战争(并查集)
  10. ctags linux,ctags --- 每天一个 Linux 命令