zoukankan      html  css  js  c++  java
  • A Story of One Country (Hard) CodeForces

    大意: 给定$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 '
    '
    #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;}
    //head
    
    
    
    const 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;
    }
    
  • 相关阅读:
    关于APP接口设计
    http协议详解-摘抄
    lnmp启动脚本
    MySQL数据库优化总结
    91、sendToTarget与sendMessage
    90、 Android UI模板设计
    Android Intent Action大汇总(转载)
    89、Android EditText 悬浮停靠
    88、android 插件开发教程(转载)
    Android Studio实用插件使用
  • 原文地址:https://www.cnblogs.com/uid001/p/11308341.html
Copyright © 2011-2022 走看看