码迷,mamicode.com
首页 > 其他好文 > 详细

3905 - Meteor

时间:2014-06-28 10:30:40      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   width   

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 = (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.

 

bubuko.com,布布扣 <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>(1bubuko.com,布布扣w, hbubuko.com,布布扣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), 1bubuko.com,布布扣nbubuko.com,布布扣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
bubuko.com,布布扣
#include"iostream"
#include"algorithm"
#include"cstdio"
using namespace std;
void updata(int x,int a,int w,int &L,int &R)
{
    if(a==0)
    {
        if(x<=0||x>=w)
          R=L-1;
    }
    else if(a>0)   //x+at=0  x+at=w;
    {
        L=max(L,-x*(2520/a));
        R=min(R,(w-x)*(2520/a));
    }
    else
    {
        L=max(L,(w-x)*(2520/a));
        R=min(R,-x*(2520/a));
    }
}
const int maxn=100000+10;
struct Event
{
    int x;
    int type;
    bool operator <(const Event &a) const
    {
        return x<a.x||(x==a.x&&type>a.type);
    }
}events[maxn*2];
int main()
{
    int t;
    scanf("%d",&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,a,b;
            scanf("%d%d%d%d",&x,&y,&a,&b);
            int L=0,R=1e9;
            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 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;
}
View Code

 

3905 - Meteor,布布扣,bubuko.com

3905 - Meteor

标签:des   style   blog   http   color   width   

原文地址:http://www.cnblogs.com/767355675hutaishi/p/3804256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!