【UVALive】3905 Meteor(扫描线)

题目

传送门:QWQ

分析

扫描线搞一搞。

按左端点排序,左端点相同时按右端点排序。

如果是左端点就$ cnt++ $,否则$ cnt-- $

统计一下$ Max $就行了

代码

#include <bits/stdc++.h>
using namespace std;
void update(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);
    }
}
const int maxn=100010;
struct Event{
    double 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);
            double L=0, R=1e9;
            update(x,a,w,L,R); update(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;
}

原文地址:https://www.cnblogs.com/noblex/p/9223548.html

时间: 2024-08-29 16:22:55

【UVALive】3905 Meteor(扫描线)的相关文章

[2016-03-20][UVALive][3905][Meteor]

时间:2016-03-20 20:14:20 星期日 题目编号:[2016-03-20][UVALive][3905][Meteor] 题目大意:给定一定大小的相框,相框的右下角为坐标原点,给定n个星星的起始位置和运动方向,问相框内最多能捕捉到多少星星 方法: 把星星的运动方向分解成x和y两个方向,计算两个方向经过相框的时间,得到每个星星在相框的时间范围,题目就转换成,最多区间相交问题 计算时间: 计算直线上x为起点,a为增量,经过边界为w的时间对应的l和r 已知 0 < x + at < w

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 owne

LA 3905 Meteor

给出一些点的初始位置(x, y)及速度(a, b)和一个矩形框,求能同时出现在矩形框内部的点数的最大值. 把每个点进出矩形的时刻分别看做一个事件,则每个点可能对应两个事件,进入事件和离开事件. 按这些事件的发生时间进行排序,然后逐个扫描,遇到进入事件cnt++,遇到离开事件--cnt,用ans记录cnt的最大值. 对时间相同情况的处理,当一个进入事件的时刻和离开事件的时刻相同时,应该先处理离开事件后处理进入事件. 因为速度(a, b)是-10~10的整数,所以乘以LCM(1,2,3,,,10)

LA - 3905 ——Meteor 流星

题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16454 1.对于每一颗流星而言,真正有意义的是它穿越矩形的有效时间,所以其实我们需要得到所有流星的有效时间 2.这样的话,原问题就转化更加具体的:某个时刻最多同时穿过多少个时间段? 解决方案: 将每一个时间区间,转化为两个事件:开始事件和结束事件.我们对所有事件按照时间排序,然后我们有一个初始化为0的tot变量计数,接着遍历这个序列,遇到开始事件就+1,遇到结束时间就

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 owne

计算几何题目分类

转载 一.基础题目 1.1 有固定算法的题目 A, 最近点对问题最近点对问题的算法基于扫描线算法.ZOJ 2107    Quoit Design    典型最近点对问题POJ    3714    Raid    变种最近点对问题 B,最小包围圆最小包围圆的算法是一种增量算法,期望是O(n).ZOJ    1450    Minimal Circle  HDU    3007    Buried memory C,旋转卡壳POJ 3608    Bridge Across Islands   

扫描线 - UVALive - 6864 Strange Antennas

Strange Antennas Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=87213 Mean: 给你一个N*N的网格,有M个雷达,每个雷达的扫射区域是一个直角边长为P的等腰直角三角形,能够向以直角顶点为中心的四个象限扫射. 雷达之间存在信号屏蔽,只有被奇数个雷达扫射到的区域才能被信号覆盖.求被信号覆盖的区域是多少. analyse: 因为给的都是整数点,这样就不涉及到计算几何了. N

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

【BZOJ】1382: [Baltic2001]Mars Maps (线段树+扫描线)

1382: [Baltic2001]Mars Maps Time Limit: 5 Sec  Memory Limit: 64 MB Description 给出N个矩形,N<=10000.其坐标不超过10^9.求其面积并 Input 先给出一个数字N,代表有N个矩形. 接下来N行,每行四个数,代表矩形的坐标. Output 输出面积并 Sample Input 2 10 10 20 20 15 15 25 30 Sample Output 225 本以为是傻逼题,没想到不容易啊- 线段树+扫描