LA 3905 Meteor 扫描线
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 <tex2html_verbatim_mark>meteors, each moving in uniform linear motion; the meteor mi <tex2html_verbatim_mark>moves along the trajectory pi + t×vi<tex2html_verbatim_mark>over time t <tex2html_verbatim_mark>, where t <tex2html_verbatim_mark>is a non-negative real value, pi <tex2html_verbatim_mark>is the starting point of mi <tex2html_verbatim_mark>and vi <tex2html_verbatim_mark>is the velocity ofmi <tex2html_verbatim_mark>. The point pi = (xi, yi) <tex2html_verbatim_mark>is represented by X <tex2html_verbatim_mark>-coordinate xi <tex2html_verbatim_mark>and Y <tex2html_verbatim_mark>-coordinate yi <tex2html_verbatim_mark>in the (X, Y) <tex2html_verbatim_mark>-plane, and the velocity vi = (ai, bi) <tex2html_verbatim_mark>is a non-zero vector with two components ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>in the (X, Y) <tex2html_verbatim_mark>-plane. For example, if pi = (1, 3) <tex2html_verbatim_mark>and vi = (-2, 5) <tex2html_verbatim_mark>, then the meteor mi <tex2html_verbatim_mark>will be at the position (0, 5.5) at time t = 0.5 <tex2html_verbatim_mark>because pi + t×vi = (1, 3) + 0.5×(-2, 5) = (0, 5.5) <tex2html_verbatim_mark>. The telescope has a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (w, h) <tex2html_verbatim_mark>. 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 <tex2html_verbatim_mark>, and p5 <tex2html_verbatim_mark>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 <tex2html_verbatim_mark>test cases. The number of test cases T <tex2html_verbatim_mark>is given in the first line of the input. Each test case starts with a line containing two integers w<tex2html_verbatim_mark>and h <tex2html_verbatim_mark>(1w, h
100, 000) <tex2html_verbatim_mark>, the width and height of the telescope frame, which are separated by single space. The second line contains an integer n <tex2html_verbatim_mark>, the number of input points (meteors), 1
n
100, 000 <tex2html_verbatim_mark>. Each of the next n <tex2html_verbatim_mark>lines contain four integers xi, yi, ai <tex2html_verbatim_mark>, and bi <tex2html_verbatim_mark>; (xi, yi) <tex2html_verbatim_mark>is the starting point pi <tex2html_verbatim_mark>and (ai, bi) <tex2html_verbatim_mark>is the nonzero velocity vector vi <tex2html_verbatim_mark>of the i <tex2html_verbatim_mark>-th meteor; xi <tex2html_verbatim_mark>and yi <tex2html_verbatim_mark>are integer values between -200,000 and 200,000, and ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>are integer values between -10 and 10. Note that at least one of ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>is not zero. These four values are separated by single spaces. We assume that all starting points pi <tex2html_verbatim_mark>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
题目大意:XOY坐标系上,给n个点(每个点的起始坐标跟速度),求在矩形区域最多能同时出现多少个点。
先把每个点在矩形上出现的时间段求出来(左右端点(左标记为0,右标记为1)push进vector容器,),二级排序。
从左只有处理各个端点,每遇到一个左端点,计数器加一;每遇到一个右端点,计数器减一。每次更新最大值。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std; const double eps=1e-;
double max(double a,double b){ return a-b>eps?a:b;}
double min(double a,double b){ return b-a>eps?a:b;} struct node
{
double x;
int i;
node(double x=,int i=):x(x),i(i){}
bool operator<(const node &A)const{
if(fabs(A.x-x)>eps) return x<A.x;
else return i>A.i;
}
};
int w,h,n;
vector<node> v; void update(int x,int a,int w,double &L,double &R)
{
if(a==)
{
if(x<= || x>=w) R=L-;
}
else if(a>)
{
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);
}
} void Push()
{
int x,y,a,b;
scanf("%d %d %d %d",&x,&y,&a,&b);
double L=,R=1e9;
update(x,a,w,L,R);
update(y,b,h,L,R);
if(R-L>eps)//经过矩形的起止时间
{
v.push_back(node(L,));
v.push_back(node(R,));
}
} int main()
{
int T,i;
scanf("%d",&T);
while(T--)
{
v.clear();
scanf("%d %d %d",&w,&h,&n);
for(i=;i<n;i++) Push();
sort(v.begin(),v.end());
int cnt=,ans=;
for(i=;i<v.size();i++)
{
if(v[i].i==) ans=max(ans,++cnt);
else cnt--;
}
printf("%d\n",ans);
}
return ;
}
LA 3905 Meteor 扫描线的更多相关文章
- UVaLive 3905 Meteor (扫描线)
题意:给定上一个矩形照相机和 n 个流星,问你照相机最多能拍到多少个流星. 析:直接看,似乎很难解决,我们换一个思路,我们认为流星的轨迹就没有用的,我们可以记录每个流星每个流星在照相机中出现的时间段, ...
- LA 3905 Meteor
给出一些点的初始位置(x, y)及速度(a, b)和一个矩形框,求能同时出现在矩形框内部的点数的最大值. 把每个点进出矩形的时刻分别看做一个事件,则每个点可能对应两个事件,进入事件和离开事件. 按这些 ...
- 【UVALive】3905 Meteor(扫描线)
题目 传送门:QWQ 分析 扫描线搞一搞. 按左端点排序,左端点相同时按右端点排序. 如果是左端点就$ cnt++ $,否则$ cnt-- $ 统计一下$ Max $就行了 代码 #include & ...
- 3905 - Meteor
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- 【转换模型+扫描线】【UVA1398】Meteor
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...
- LA 3029 - City Game (简单扫描线)
题目链接 题意:给一个m*n的矩阵, 其中一些格子是空地(F), 其他是障碍(R).找一个全部由F 组成的面积最大的子矩阵, 输出其面积乘以3的结果. 思路:如果用枚举的方法,时间复杂度是O(m^2 ...
- LA 4127 - The Sky is the Limit (离散化 扫描线 几何模板)
题目链接 非原创 原创地址:http://blog.csdn.net/jingqi814/article/details/26117241 题意:输入n座山的信息(山的横坐标,高度,山底宽度),计算他 ...
随机推荐
- WINDOWS-API:关于线程CreateThread,_beginthead(_beginthreadex),AfxBeginThread
[转]windows多线程编程CreateThread,_beginthead(_beginthreadex)和AfxBeginThread的区别 在Windows的多线程编程中,创建线程的函数主要有 ...
- Maven搭建Struts2+Spring3+Hibernate4框架
做了三年多的JavaEE开发了,在平时的JavaEE开发中,为了能够用最快的速度开发项目,一般都会选择使用Struts2,SpringMVC,Spring,Hibernate,MyBatis这些开源框 ...
- Bootstrap标签页(Tab)插件事件
事件 下表列出了标签页(Tab)插件中要用到的事件.这些事件可在函数中当钩子使用. 事件 描述 实例 show.bs.tab 该事件在标签页显示时触发,但是必须在新标签页被显示之前.分别使用 even ...
- 14Shell脚本—判断语句
判断语句 Shell脚本中的条件测试语法可以判断表达式是否成立,若条件成立则返回数字0,否则便返回其他随机数值. 条件测试语法的执行格式为 [ 条件表达式 ],切记,条件表达式两边均应有一个空格. 条 ...
- mysql主主复制汇总整理
mysql主主复制汇总整理 一.Mysql主主.主从复制主要思路: 1.mysql复制实质: 就是其他的MySQL数据库服务器将这个数据变更的二进制日志在本机上再执行一遍,因此非常重要的一点是mysq ...
- NFS搭建
一.环境 nfsserver01:192.168.127.100 centos7.3 nfsclient01:192.168.127.101 centos7.3 二.NFS原理 三.安装测试 1. ...
- uvm transaction modeling
1.what is transaction? network transactions tcp/ip wifi 3g/4g bus transactions amba-ahb/apb/axi pci/ ...
- 百度地图和高德地图的API视频教程
学习地址: http://www.houdunren.com/houdunren18_lesson_152?vid=10228 素材地址: https://gitee.com/houdunwang/v ...
- 通过代码链接ftp上传下载删除文件
因为我的项目是Maven项目,首先要导入一个Maven库里的包:pom.xml <dependency> <groupId>com.jcraft</ ...
- Python学习笔记:py2exe打包Python程序
使用py2exe将一个Python程序打包成一个exe程序,这样Python程序也可以在没有安装Python的环境中运行Python程序了.使用这个工具需要写一个用于打包的setup.py文件(名称可 ...