hdu 4429 Split the Rectangle
来源:互联网 发布:阿里云 404 编辑:程序博客网 时间:2024/04/28 05:54
读懂题意之后就是简单的暴力找一个最小的矩形去包围这两个点,然后把这个矩形内部的点全部去掉,就可以得出答案。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=2e3+9,inf=1e9;int n,q;int lonl,lonr;struct{ int x1,x2,y1,y2;}line[maxn];struct{ int x1,x2,y1,y2;}rec[maxn<<1];void push(int x1,int x2,int y1,int y2){ rec[++lonr].x1=x1; rec[lonr].x2=x2; rec[lonr].y1=y1; rec[lonr].y2=y2;}void pushline(int x1,int x2,int y1,int y2){ line[++lonl].x1=x1; line[lonl].x2=x2; line[lonl].y1=y1; line[lonl].y2=y2;}void insert(int x1,int x2,int y1,int y2){ int up=inf,down=-inf; if(x1==x2) { for(int i=1;i<=lonl;i++) { if(line[i].y1<=y1&&line[i].y2>=y2) { if(line[i].x1>x1&&line[i].x1<up) up=line[i].x1; if(line[i].x1<x1&&line[i].x1>down) down=line[i].x1; } } push(down,x1,y1,y2); push(x1,up,y1,y2); } else { for(int i=1;i<=lonl;i++) { if(line[i].x1<=x1&&line[i].x2>=x2) { if(line[i].y1>y1&&line[i].y1<up) up=line[i].y1; if(line[i].y1<y1&&line[i].y1>down) down=line[i].y1; } } push(x1,x2,down,y1); push(x1,x2,y1,up); }}void work(int &x1,int &x2,int &y1,int &y2){ if(x1>x2) swap(x1,x2); if(y1>y2) swap(y1,y2);}bool chk(int xd,int xu,int yd,int yu,int t){ bool flag=false; if(line[t].x1<xd) return false; else if(line[t].x1>xd&&line[t].x1<xu) flag=true; if(line[t].x2>xu) return false; else if(line[t].x2>xd&&line[t].x2<xu) flag=true; if(line[t].y1<yd) return false; else if(line[t].y1>yd&&line[t].y1<yu) flag=true; if(line[t].y2>yu) return false; else if(line[t].y2>yd&&line[t].y2<yu) flag=true; return flag;}void solve(int x1,int x2,int y1,int y2){ int xd,xu,yd,yu; int now=inf; for(int i=1;i<=lonr;i++) if(rec[i].x1<=x1&&rec[i].x2>=x2&&rec[i].y1<=y1&&rec[i].y2>=y2) { int tmp=rec[i].x2+rec[i].y2-rec[i].x1-rec[i].y1; if(now>tmp) { xd=rec[i].x1; xu=rec[i].x2; yd=rec[i].y1; yu=rec[i].y2; now=tmp; } } int ans=n+1; for(int i=1;i<=lonl;i++) { if(chk(xd,xu,yd,yu,i)) ans--; } cout<<ans<<endl;}int main(){// freopen("in.txt","r",stdin); int x1,x2,y1,y2; while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)!=EOF) { lonl=lonr=0; work(x1,x2,y1,y2); push(x1,x2,y1,y2); pushline(x1,x1,y1,y2); pushline(x2,x2,y1,y2); pushline(x1,x2,y1,y1); pushline(x1,x2,y2,y2); scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); work(x1,x2,y1,y2); insert(x1,x2,y1,y2); pushline(x1,x2,y1,y2); } for(int i=1;i<=q;i++) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); work(x1,x2,y1,y2); solve(x1,x2,y1,y2); } } return 0;}
- hdu 4429 Split the Rectangle
- hdu 4429 Split the Rectangle
- HDU 4429 Split the Rectangle(暴力)
- Split the Rectangle HDU
- ***HDU 4429 - Split the Rectangle(LCA'暴力求解)
- [HDU 4429]Split the Rectangle[LCA][二叉树]
- hdu 4429 Split the Rectangle(lca+二叉树)
- zoj 3664 Split the Rectangle
- hdu4429 Split the Rectangle(LCA)
- ZOJ Problem Set - 3664 Split the Rectangle
- 搜索起步—— Rectangle Split HihoCoder
- LeetCode_492. Construct the Rectangle
- LEETCODE--Construct the Rectangle
- Construct the Rectangle
- leetcode492: Construct the Rectangle
- 492. Construct the Rectangle
- 【leetcode】Construct the Rectangle
- 492. Construct the Rectangle
- 在android布局中使用include和merge标签
- Floyd All Shortest Path 所有最短路径的查找 C++程序
- jetty的线程池实现QueuedThreadPool
- hdu 2680 Choose the best route
- NYOJ-67-三角形面积-2013年08月21日09:15:13
- hdu 4429 Split the Rectangle
- IOS 四种保存数据的方式
- 必须知道的HTML5十件事
- LeetCode
- openfire使用自定义用户表
- kvo和kvc
- 第11周项目6-*#图
- NYOJ-655-光棍的yy-2013年08月21日16:50:16
- oracle中的游标学习