LA 3905(扫描线)
来源:互联网 发布:越南常用聊天软件 编辑:程序博客网 时间:2024/05/24 01:38
Meteor
64-bit integer IO format: %lld Java class name: Main
[PDF Link]
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 velocityvi = (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 exam! ple, 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 w and h (1w, h100, 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 xi, yi, ai , and bi ; (xi, yi) is the starting point pi and (ai, bi) 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
Source
给出一个矩形,还有n个星星,星星可以看成质点,告诉你星星的坐标和速度,求矩形最多能包含多少个星星(边界上的不算),处理出每个星星在矩形里的时间区间,然后用扫描线。大白P47.
#include <bits/stdc++.h>using namespace std;const int maxn = 1e5 + 10;struct Node{ double x; bool Type; bool operator < (const Node & rhs) const { if(x == rhs.x) return Type > rhs.Type; return x < rhs.x; }}Item[maxn<<1];void Modify(int pos,int w,double v,double &L,double &R){ if(v == 0) { if(pos <= 0 || pos >= w) R = L-1; return ; }else if(v > 0) { L = max(L,-pos/v); R = min(R,(w-pos)/v); }else { L = max(L,(w-pos)/v); R = min(R,-pos/v); }}int main(){ int T; scanf("%d",&T); for(int cas = 1; cas <= T; ++cas) { int w,h;scanf("%d%d",&w,&h); int n;scanf("%d",&n); int tot = 0; for(int i = 0; i < n; ++i) { int x,y,dx,dy; scanf("%d%d%d%d",&x,&y,&dx,&dy); double L = 0, R = 1e10; Modify(x,w,dx,L,R); Modify(y,h,dy,L,R); //printf("%.2f %.2f\n",L,R); if(R > L) { Item[tot++] = (Node) {L,0}; Item[tot++] = (Node) {R,1}; } } sort(Item,Item+tot); int cnt = 0,ans = 0; for(int i = 0; i < tot; ++i) { if(Item[i].Type == 0) { ++cnt; ans = max(ans,cnt); }else --cnt; } printf("%d\n",ans); } return 0;}
- LA 3905(扫描线)
- LA 3905 Meteor 扫描线 -
- LA 3905 Meteor [扫描线]
- LA 3905 Meteor / 区间扫描
- LA 3905 Meteor (排序+扫描法)
- LA 3695 Distant Galaxy(扫描线)
- LA 3695 Distant Galaxy 扫描线 -
- LA 3029 City Game [扫描线][DP]
- LA 3095 扫描法 线性
- LA 4851 Restaurant (扫描法)
- LA 4356 Fire-Control System (扫描法)
- LA - 5734(hdu - 4162) - Shape Number(指针扫描+贪心)
- POJ 1901 | LA 2963 | UVa 1325 - Hypertransmission (思维 扫描)
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- LA 3695 Distant Galaxy (部分枚举+扫描法)
- LA 3905(p45)----Meteor
- UVa live 3905 扫描线
- la la la, la la la
- iw 工具下载地址
- 内核艺术系列:绚丽整个php的zend(1)
- Apache common deamon
- RMQ算法
- 个人笔记-从零开始IOS开发_C语言基础1
- LA 3905(扫描线)
- 最小生成树Prim和Kruskal算法
- C++类与对象基础
- java记录日志功能
- 折线图(六)绘制真正可用的折线图
- [LeetCode]Unique Paths II
- 【Arduino】开发入门教程【五】Hello Arduino
- Nginx的反向代理与负载均衡
- 在Xcode中资源文件要以folder references(蓝色文件夹)而非groups(黄色文件夹)形式添加