UVA 1398

1398 – Meteor

Time limit: 3.000 seconds

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 of mi . 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 example, 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 (1wh100, 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 xiyiai , and bi ; (xiyi) is the starting point pi and (aibi)is the nonzero velocity vector vi of the i -th meteor; xi and yi are integer values between -200,000 and 200,000, and ai and 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题目大意是:给你一个矩形照相机,还有n个流星的初始位置和速度,求能照到流星最多的时刻,注意边界上的点不会被照到。输入格式;第一行输入测试案例数T;每组数据的第一行为两个整数w和h;第二行为流星的个数n;以下n行每行用4个整数xi,yi,ai,bi来描述一个流星,其中(xi,yi)是初始位置,(ai,bi)是速度,ai和bi不同时为0.输出格式:对于每组数据,输出能照到的流星个数的最大值。解题思路:(1)、我们将每个流星在矩形照相机中出现的时间段,转换成 n个区间,然后求出一个数t,使得包含它的区间数最多;         (2)、进行排序         (3)、我们用一个扫描先从区间的左端向右端移动,当遇到左端点时就加1,遇到右端点时就减1;

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 const int maxn=100010;
 5 void fun(int x,int a,int w,double &L,double &R)
 6 {
 7     if(a==0)
 8         {if(x<=0||x>=w) R=L-1;}
 9     else
10     {
11         if(a>0)
12         {
13             L=max(L,-(double)x/a);
14             R=min(R,double(w-x)/a);
15         }
16         else
17             {
18                L=max(L,double(w-x)/a);
19                R=min(R,-(double)x/a);
20             }
21     }
22 }
23 struct Event
24 {
25     double x;
26     int type;
27     bool operator < (const Event &a)const
28     {
29         if(x!=a.x)
30            return x<a.x;
31         else
32           return type>a.type;
33     }
34 }events[maxn*2];
35 int main()
36 {
37     int T;
38     cin>>T;
39     while(T--)
40     {
41         int w,h,n,e=0;
42         cin>>w>>h>>n;
43         for(int i=0;i<n;i++)
44         {
45             int x,y,a,b;
46             cin>>x>>y>>a>>b;
47             double L=0,R=1e9;
48             fun(x,a,w,L,R);
49             fun(y,b,h,L,R);
50             if(R>L)
51             {
52                events[e++]={L,0};
53                events[e++]={R,1};
54             }
55          }
56          sort(events,events+e);
57          int cnt=0,ans=0;
58          for(int i=0;i<e;i++)
59          {
60             if(events[i].type==0)
61                ans=max(ans,++cnt);
62          else
63             cnt--;
64          }
65           cout<<ans<<endl;
66     }
67     return 0;
68 }

时间: 2024-12-09 21:59:49

UVA 1398的相关文章

UVA之1398 - 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

UVA 10457 - Magic Car【最小瓶颈树】

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=600&problem=1398&mosmsg=Submission+received+with+ID+14106648 题意: m条路,每条路上必须维持速度v,现在有一辆车,启动能量和结束能量为a, b,途中消耗能量为经过路径最大速度减去最小速度,现在每次循环给

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica

[2016-02-03][UVA][514][Rails]

时间:2016-02-03 22:24:52 星期三 题目编号:UVA 514 题目大意:给定若干的火车(编号1-n),按1-n的顺序进入车站, 给出火车出站的顺序,问是否有可能存在 分析:    FIFO,用栈模拟一遍即可, 方法:    根据输入的顺序,从1-n开始,当前操作的为i 如果i是当前对应的编号,那么直接跳过(进入B) 如果不是,根据当前需求的编号,小于i,就从栈顶弹出一个元素, 看这个元素是否是需求的,是则继续.否则NO 1 2 3 4 5 6 7 8 9 10 11 12 13