USACO:Shaping Regions

来源:互联网 发布:mac 重新安装程序 编辑:程序博客网 时间:2024/05/17 23:17
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<queue>#define mp make_pairusing namespace std;typedef long long lng;typedef pair<int, int> pii;struct seg{  int l,r;  seg(){}  seg(int x,int y){l=x,r=y;}};int Min(int x,int y){if(x<y) return x;return y;}int Max(int x,int y){if(x>y) return x;return y;}struct rec{  seg w,h;  int col;  rec(){}  rec(seg x,seg y,int cc){w=x,h=y,col=cc;}};bool is_1(seg x,seg y){    return x.l<=y.l?y.l<x.r:x.l<y.r;}bool is_2(rec x,rec y){    return is_1(x.w,y.w)&&is_1(x.h,y.h);}seg seek_insect(seg x,seg y){  return seg(Max(x.l,y.l),Min(x.r,y.r));}vector<rec> c,now;void f(rec x,rec &y) //x changed{    if(is_2(x,y))    {        seg w1=seek_insect(x.w,y.w),h1=seek_insect(x.h,y.h);      if(w1.l>x.w.l){c.push_back(rec(seg(x.w.l,w1.l),x.h,x.col));}      if(w1.r<x.w.r){c.push_back(rec(seg(w1.r,x.w.r),x.h,x.col));}      if(h1.l>x.h.l){c.push_back(rec(w1,seg(x.h.l,h1.l),x.col));}      if(h1.r<x.h.r){c.push_back(rec(w1,seg(h1.r,x.h.r),x.col));}    }   else  c.push_back(x);}

原创粉丝点击