UVA 3905 计算几何<扫描法> <求一条线与矩形的交>
来源:互联网 发布:青岛知豆在哪租 编辑:程序博客网 时间:2024/05/21 06:37
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <climits>#include <cstdlib>#include <ctime>using namespace std;const int maxn = 100000 + 10;struct event{double x;int type;bool operator < (const event& a )const{return x < a.x || (x == a.x && type > a.type);}}events[maxn*2];void fun(int x,int a,int w,double& l,double& r)//求流星的在矩形里的时间。分别带入x和y这样求得两个区间的交集{if(a == 0){if(x <= 0 || x >= w) r = l - 1;}else if(a > 0) {l = max(l,-(double) x / a);r = min(r,(double)(w - x)/a);}else {l = max(l,(double)(w-x) / a);r = min(r,-(double)x / a);}}int main(){int t;cin >> t;while(t--){int w,h,n,e = 0;scanf("%d%d%d",&w,&h,&n);for(int i = 0; i < n; i++){int x,y,vx,vy;scanf("%d%d%d%d",&x,&y,&vx,&vy);double l = 0, r = 1e9;fun(x,vx,w,l,r);fun(y,vy,h,l,r);if(r > l){events[e++] = (event){l,0};events[e++] = (event){r,1};}}sort(events,events+e);int cnt = 0,ans = 0;//排序后扫描扫描的格点就是每一区间的开始和结尾for(int i = 0; i < e; i++){if(events[i].type == 0) ans = max(ans,++cnt);else cnt --;}printf("%d\n",ans);}return 0;}
UVALive - 3905
Description
The famous Korean internet company nhn has provided an internet-based photo service which allows The famous Korean internet company users to directly take a photo of an astronomical phenomenon in space by controlling a high-performance telescope owned by nhn. A few days later, a meteoric shower, known as the biggest one in this century, is expected. nhn has announced a photo competition which awards the user who takes a photo containing as many meteors as possible by using the photo service. For this competition, nhn provides the information on the trajectories of the meteors at their web page in advance. The best way to win is to compute the moment (the time) at which the telescope can catch the maximum number of meteors.
You have n meteors, each moving in uniform linear motion; the meteor mi moves along the trajectory pi + t×vi over time t , where t is a non-negative real value, pi is the starting point of mi and vi is the velocity ofmi . The point pi = (xi, yi) is represented by X -coordinate xi and Y -coordinate yi in the (X, Y) -plane, and the velocity vi = (ai, bi) is a non-zero vector with two components ai and bi in the (X, Y) -plane. For example, if pi = (1, 3) and vi = (-2, 5) , then the meteor mi will be at the position (0, 5.5) at time t = 0.5 because pi + t×vi = (1, 3) + 0.5×(-2, 5) = (0, 5.5) . The telescope has a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (w, h) . Refer to Figure 1. A meteor is said to be in the telescope frame if the meteor is in the interior of the frame (not on the boundary of the frame). For exam! ple, in Figure 1, p2, p3, p4, and p5 cannot be taken by the telescope at any time because they do not pass the interior of the frame at all. You need to compute a time at which the number of meteors in the frame of the telescope is maximized, and then output the maximum number of meteors.
Input
Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers wand h(1w, h100, 000) , the width and height of the telescope frame, which are separated by single space. The second line contains an integer n , the number of input points (meteors), 1n100, 000 . Each of the next n lines contain four integers xi, yi, ai , and bi ; (xi, yi) is the starting point pi and (ai, bi) is the nonzero velocity vector vi of the i -th meteor; xi and yi are integer values between -200,000 and 200,000, and aiand bi are integer values between -10 and 10. Note that at least one of ai and bi is not zero. These four values are separated by single spaces. We assume that all starting points pi are distinct.
Output
Your program is to write to standard output. Print the maximum number of meteors which can be in the telescope frame at some moment.
Sample Input
2 4 2 2 -1 1 1 -1 5 2 -1 -1 13 6 7 3 -2 1 3 6 9 -2 -1 8 0 -1 -1 7 6 10 0 11 -2 2 1 -2 4 6 -1 3 2 -5 -1
Sample Output
1 2
FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
All Copyright Reserved ©2010-2014 HUST ACM/ICPC TEAM
Anything about the OJ, please ask in the forum, or contact author:Isun
Server Time:
- UVA 3905 计算几何<扫描法> <求一条线与矩形的交>
- 蓝桥杯 矩形区域的交和并 计算几何
- hdu1828&poj1177(线段树求矩形交周长,扫描线)
- poj 1177 线段树+扫描线 求矩形交的周长
- poj 1389 线段树+扫描线 求矩形交的面积
- 计算几何 多边形的交与并
- 扫描线矩形面积交
- hdu1255 覆盖的面积(矩形面积交+扫描线)
- 射线与三角形求交的计算
- 计算几何——线段求交
- poj3304(计算几何+线段求交)
- hdu 1086 计算几何 线段求交
- CSU 1812 三角形和矩形(计算几何,多边形面积交)
- [从头学数学] 第265节 [计算几何] 多线段求交点(扫描线法)
- HDU 5251 矩形面积 (计算几何+旋转卡壳求覆盖凸包的最小矩形面积)
- HDU3867 计算几何扫描线
- HDU3867 计算几何扫描线
- <模板><计算几何>半平面求交学习小记
- Python学习手册(第四版)学习笔记(三)编写运行“Hello ,world!”
- Unity3d优化技巧
- ThinkAndroid框架 网络状态监听原理
- view, surfaceView, invalidate, postInvalidate, 刷新屏幕
- Map排序问题
- UVA 3905 计算几何<扫描法> <求一条线与矩形的交>
- Android 之后台推送
- linux下tar、zip等压缩、解压命令
- 十大微信推广办法
- zoj 1203 Swordfish Prim算法
- 不锈钢是含铬超过wcr12%Fe-Cr合金
- python爬虫框架Scrapy入门:安装
- 关于getElementsByClassName
- Handler和Looper是怎样绑定到一起的?