Uva---1398Meteor

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 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 of mi <tex2html_verbatim_mark>. The point pi = (xiyi) <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 = (aibi) <tex2html_verbatim_mark>is a non-zero vector with two components ai <tex2html_verbatim_mark>and bi <tex2html_verbatim_mark>in the (XY) <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 (wh) <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, p2p3p4 <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.

 

\epsfbox{p3905.eps}<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$ \le$wh$ \le$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$ \le$n$ \le$100, 000<tex2html_verbatim_mark>. Each of the next n <tex2html_verbatim_mark>lines contain four integers xiyiai <tex2html_verbatim_mark>, and bi <tex2html_verbatim_mark>; (xiyi) <tex2html_verbatim_mark>is the starting point pi <tex2html_verbatim_mark>and(aibi) <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


/*
思路:
  建模,先将每颗流星的位置坐标与其速度,化简为其在矩形相机内出现的时间。
  之后按照每颗流星出现在相机视野内的时间,和其从相机视野内消失的顺序给维护的数组排序,之后维护一个ans,遍历一遍即可得到答案。

*/

代码:
#include<stdio.h>
#include<string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=100010;
//更新每颗流星的坐标为一个时间区间;
int updata(int x,int a,int w,double &L,double &R){
    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);
    }
}
struct Event{
    double x;
    int type;
    bool operator < (const Event &a) const{
        return x<a.x || (x==a.x && type > a.type);
    }
}events[N*2];
int main()
{
    int i,T;int w,h,n;int x,y,a,b;
    freopen("in.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d %d",&w,&h);
        scanf("%d",&n);int e=0;
        for(i=0;i<n;i++){
            double L=0,R=1e9;
            scanf("%d %d %d %d",&x,&y,&a,&b);
            updata(x,a,w,L,R);
            updata(y,b,h,L,R);
            if(R>L){
                events[e++]= (Event) {L,0};
                events[e++]= (Event) {R,1};
            }
        }
        sort(events,events+e);
        int num=0,ans=0;
        for(i=0;i<e;i++)
            if(events[i].type==0) ans=max(ans,++num);
            else num--;
        printf("%d\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值