hdu1264 Counting Squares
来源:互联网 发布:网络电话卡app制作 编辑:程序博客网 时间:2024/06/07 19:43
Problem Description
Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the line
5 8 7 10
specifies the rectangle who’s corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.
Input
The input format is a series of lines, each containing 4 integers. Four -1’s are used to separate problems, and four -2’s are used to end the last problem. Otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle.
Output
Your output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.
Sample Input
5 8 7 10
6 9 7 8
6 8 8 11
-1 -1 -1 -1
0 0 100 100
50 75 12 90
39 42 57 73
-2 -2 -2 -2
Sample Output
8
10000
分析:
扫描线裸题
tip
All coordinates will be integers in the range 0 to 100.
但是我用的int就是蜜汁RE,
把所有和坐标有关的变量类型变成double之后
就顺利A了
哪位dalao帮我解答一下啊。。。
还需要注意的一点是:
这里写代码片#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const double eps=1e-8;const int N=310;struct node{ int x,y,s; double ml,mr,len;};node t[N<<2];struct nd{ double x,ya,yb; int ff;};nd li[N<<1];int n,tot;double yi[N<<1];int cmp(const nd &a,const nd &b){ return a.x-b.x<eps;}void build(int bh,int l,int r){ t[bh].x=l; t[bh].y=r; t[bh].ml=yi[l]; t[bh].mr=yi[r]; t[bh].s=t[bh].len=0; if (l==r-1) return; int mid=(l+r)>>1; build(bh<<1,l,mid); build(bh<<1|1,mid,r);}void update(int bh){ if (t[bh].s>0) t[bh].len=t[bh].mr-t[bh].ml; else if (t[bh].x==t[bh].y-1) t[bh].len=0; /// else t[bh].len=t[bh<<1].len+t[bh<<1|1].len;}void add(int bh,nd p){ if (t[bh].ml==p.ya&&t[bh].mr==p.yb) { t[bh].s+=p.ff; update(bh); return; } if (p.yb<=t[bh<<1].mr) add(bh<<1,p); else if (p.ya>=t[bh<<1|1].ml) add(bh<<1|1,p); else { nd temp; temp=p; temp.yb=t[bh<<1].mr; add(bh<<1,temp); temp=p; temp.ya=t[bh<<1|1].ml; add(bh<<1|1,temp); } update(bh); //}int main(){ double x=0,y=0,xx=0,yy=0; scanf("%lf%lf%lf%lf",&x,&y,&xx,&yy); while (x!=-2&&y!=-2&&xx!=-2&&yy!=-2) { tot=0; while (x!=-1&&y!=-1&&xx!=-1&&yy!=-1&&x!=-2&&y!=-2&&xx!=-2&&yy!=-2) { if (x>xx) swap(x,xx); if (y>yy) swap(y,yy); //给出的不一定是左下角和右上角 tot++; yi[tot]=y; li[tot].x=x;li[tot].ya=y;li[tot].yb=yy;li[tot].ff=1; tot++; yi[tot]=yy; li[tot].x=xx;li[tot].ya=y;li[tot].yb=yy;li[tot].ff=-1; scanf("%lf%lf%lf%lf",&x,&y,&xx,&yy); } sort(yi+1,yi+1+tot); sort(li+1,li+1+tot,cmp); build(1,1,tot); add(1,li[1]); double sum=0; for (int i=2;i<=tot;i++) { sum+=(t[1].len*(li[i].x-li[i-1].x)); add(1,li[i]); } printf("%0.0lf\n",sum); if (x==-2&&y==-2&&xx==-2&&yy==-2) break; scanf("%lf%lf%lf%lf",&x,&y,&xx,&yy); } return 0;}
- hdu1264 Counting Squares
- hdu1264 Counting Squares
- hdu1264 Counting Squares(线段树+离散化)
- Counting Squares
- HDU 1264 Counting Squares
- HDU 1264 Counting Squares
- hdu 1256 Counting Squares
- HDU 1264 Counting Squares
- hdu 1264 Counting Squares
- HDU 1264 Counting Squares
- Counting Squares(1264)
- HDU 1264 Counting Squares
- 1264:Counting Squares
- hdu 1264 Counting Squares
- UVALive 6602 Counting Lattice Squares
- hdu1246 Counting Squares(暴力hash)
- hdu 1264 counting the squares
- ZOJ 3107 Counting Squares//计算几何
- oracle表空间的管理
- 地址
- API使用
- Nodejs 进阶:Express 常用中间件 body-parser 实现解析
- crontab 详细用法 定时任务
- hdu1264 Counting Squares
- arm启动模式
- Unity入门学习 //01_Unity界面分布
- linux export指令
- 深入java虚拟机面试
- BroadcastReceiver开机启动和动态注册
- 流形学习(Manifold Learning)理解
- Python3之自动登录
- CCF试题——画图