hunnu_11287 Thinking Inside the Box (简单几何)
来源:互联网 发布:天猫淘宝网连衣裙 编辑:程序博客网 时间:2024/06/11 05:34
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11287&courseid=109
题意:
在地球上给一些一矩形,再给一些查询矩形,问哪些矩形与查询矩形相交。
思路:
考虑地球是圆的,变成平面坐标系后经度小于-180和大于180的都要扩展下,
题目说给的纬度、经度的矩形是上顶点和其对角线。换成坐标后是Y坐标为
经度。通过—+360来移到一个平面来。
我的代码:
/*program:hunnu_11287author:BlackAndWhile*/#include<stdio.h>#include<math.h>struct point{ int x,y;}a[100001][2],b[100001][2],tb[2],ansa[100001][2];int T,n,m,i,j,ans;int bl[100001];int cross(point a[2],point b[2])//判断矩形交 { int i,j; if(a[1].y<=b[1].y&&a[1].y>=b[0].y&&((a[1].x<=b[1].x&&a[0].x>=b[0].x)||(a[1].x>=b[1].x&&a[1].x<=b[0].x)||(a[0].x<=b[0].x&&a[0].x>=b[1].x))) return 1; if(a[0].y<=b[1].y&&a[0].y>=b[0].y&&((a[1].x<=b[1].x&&a[0].x>=b[0].x)||(a[1].x>=b[1].x&&a[1].x<=b[0].x)||(a[0].x<=b[0].x&&a[0].x>=b[1].x))) return 1; if(a[1].x>=b[1].x&&a[1].x<=b[0].x&&((a[1].y>=b[1].y&&a[0].y<=b[0].y)||(a[1].y<=b[1].y&&a[1].y>=b[0].y)||(a[0].y>=b[0].y&&a[0].y<=b[1].y))) return 1; if(a[0].x>=b[1].x&&a[0].x<=b[0].x&&((a[1].y>=b[1].y&&a[0].y<=b[0].y)||(a[1].y<=b[1].y&&a[1].y>=b[0].y)||(a[0].y>=b[0].y&&a[0].y<=b[1].y))) return 1; return 0;}int main(){ scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d,%d %d,%d",&a[i][0].x,&a[i][0].y,&a[i][1].x,&a[i][1].y); ansa[i][0]=a[i][0]; ansa[i][1]=a[i][1]; if(a[i][0].y>a[i][1].y) a[i][1].y+=360;//犯2了,我把原始数据改了,一直WA这里 } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%d,%d %d,%d",&b[i][0].x,&b[i][0].y,&b[i][1].x,&b[i][1].y); if(b[i][0].y>b[i][1].y) b[i][1].y+=360; bl[i]=0; } ans=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(cross(a[i],b[j])||cross(b[j],a[i])) { bl[i]=1; ans=1; break; } else { tb[0]=b[i][0];tb[1]=b[i][1]; tb[0].y-=360;tb[1].y-=360;//查询区间左移360 if(cross(a[i],tb)||cross(tb,a[i])) { bl[i]=1; ans=1; break; } tb[0].y+=720;tb[1].y+=720;//右移360 if(cross(a[i],tb)||cross(tb,a[i])) { bl[i]=1; ans=1; break; } } } } if(ans) { for(i=0;i<n;i++) if(bl[i]) printf("%d,%d %d,%d\n",ansa[i][0].x,ansa[i][0].y,ansa[i][1].x,ansa[i][1].y); } else printf("No data found.\n"); printf("\n"); } return 0;}
- hunnu_11287 Thinking Inside the Box (简单几何)
- LightOJ 1297 Largest Box【简单计算几何】
- Equipment Box(计算几何)
- zoj-2559 The Smart Bomb 简单几何
- 【POJ2504】Bounding box(计算几何)
- Inside the Native API
- Inside the Whale
- Inside the Native API
- Inside the Linux scheduler
- Inside the blackbox -- notes
- inside the c++ object
- uva_12069_Robots inside the Labyrinth_TLE
- UVA - 10250 - The Other Two Trees (简单计算几何)
- [hdu 2826] The troubles of lmy [简单计算几何 - 相似]
- The tools of thinking
- the thinking of coding
- the thinking,,,damn it
- The CSS Box Model
- 7艘中国军舰穿过冲绳海域驶向太平洋
- ANDROID的ActionBar及菜单机制
- VS 和 VAssistX 常用快捷键
- 【面试】一些排序算法代码
- 香港撞船事故调查需半年 11名遇难者名单公布
- hunnu_11287 Thinking Inside the Box (简单几何)
- OpenCV 编程入门
- 外媒称中国现行社保制度"劫贫济富"
- 我发誓一辈子也不坐你的车
- 基于ActiveX和Applet的影像浏览器的实现
- GCC___attribute__关键字和字节对齐
- 线段树——Powered By NotOnlySuccess
- thinkphp 引用图片类
- 关于流行的几点思考——《引爆点》读书笔记