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.
<tex2html_verbatim_mark>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>(1
w, 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座山的信息(山的横坐标,高度,山底宽度),计算他 ...
随机推荐
- JavaScript——图片懒加载
前言 有一个朋友问我这个问题,刚好有时间,现在就简单的写个Demo~ github | https://github.com/wangyang0210/bky/tree/picLoadLazy 内容 ...
- MySQL中同时存在创建和更新时间戳字段解决方法浅析
MySQL中同时存在创建和更新时间戳字段解决方法浅析 明确我的MySQL版本.mysql> SELECT VERSION();+------------+| VERSION() |+------ ...
- iOS 通过storyboard设置UIView或者其他layer图层的圆角
通常我们给Button或者UIView添加圆角是通过如下代码进行实现的 self.button.layer.cornerRadius=10; 但是如果你是使用的故事版或者xib进行设计视图的话,实际上 ...
- 【数学 BSGS】bzoj2242: [SDOI2011]计算器
数论的板子集合…… Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最 ...
- Git基本操作笔记:初始化,用户设置,撤销修改
1. Git 初始化 git init git remote add repos_name repos_url git add . git commit -m 'commit message' gi ...
- Golang ioutil读写文件测试
运用 ioutil.ReadFile .ioutil.WriteFile package main import ( "io/ioutil" "log" &qu ...
- python入门:print打印输出的用法
#!/usr/bin/python # -*- coding:utf-8 -*- # print打印输出的用法 print("holle,world!") print(1) pri ...
- 解决linux不能解压rar格式压缩包
1download rarlinux-x64-5.3.0.tar.gz data package 2.tar xvf rarlinux-64-5.3.0.tar.gz 3. cd rar and th ...
- nrf51822微信开发入门学习笔记1:开始前的准备
参考:(id:love--baby)https://blog.csdn.net/hunhun1122/article/details/68922493 微信硬件平台:https://iot.weixi ...
- Three displays CodeForces - 987C (dp)
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...