题意:给定上一个矩形照相机和 n 个流星,问你照相机最多能拍到多少个流星。

析:直接看,似乎很难解决,我们换一个思路,我们认为流星的轨迹就没有用的,我们可以记录每个流星每个流星在照相机中出现的时间段,

然后我们可以枚举时间段么?不行,这个是实数集上的,所以我们用扫描线,就相当于在x轴上有n个区间,我们从左到右拿一个竖线来扫描,

如果找到一个左端点,那么就加1,找到一个右端点就减1,注意,我们在排序时,要先按左端点排,再按右端点,不断更新答案即可,

并用我们可以避免使用浮点数。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int x, id;
Node() { }
Node(int xx, int i) : x(xx), id(i) { }
bool operator < (const Node &p) const{
return x < p.x || (x == p.x && id > p.id);
}
};
Node a[maxn<<1];
int l, r; void update(int x, int a, int w){
if(!a){
if(x <= 0 || x >= w) r = l - 1;
}
else if(a > 0){
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);
}
} int main(){
int T; cin >> T;
while(T--){
int w, h;
int cnt = 0;
scanf("%d %d", &w, &h);
int x, y, s, t;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d %d %d %d", &x, &y, &s, &t);
l = 0, r = 1e9;
update(x, s, w);
update(y, t, h);
if(l < r){
a[cnt++] = Node(l, 0);
a[cnt++] = Node(r, 1);
}
}
sort(a, a + cnt);
int ans = 0;
int num = 0;
for(int i = 0; i < cnt; ++i){
if(!a[i].id) ++num;
else --num;
ans = max(ans, num);
}
printf("%d\n", ans);
}
return 0;
}

UVaLive 3905 Meteor (扫描线)的更多相关文章

  1. LA 3905 Meteor 扫描线

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  2. 【UVALive】3905 Meteor(扫描线)

    题目 传送门:QWQ 分析 扫描线搞一搞. 按左端点排序,左端点相同时按右端点排序. 如果是左端点就$ cnt++ $,否则$ cnt-- $ 统计一下$ Max $就行了 代码 #include & ...

  3. 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...

  4. 3905 - Meteor

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  5. LA 3905 Meteor

    给出一些点的初始位置(x, y)及速度(a, b)和一个矩形框,求能同时出现在矩形框内部的点数的最大值. 把每个点进出矩形的时刻分别看做一个事件,则每个点可能对应两个事件,进入事件和离开事件. 按这些 ...

  6. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  7. 【转换模型+扫描线】【UVA1398】Meteor

    The famous Korean internet company nhn has provided an internet-based photo service which allows The ...

  8. UVALive 4221 Walk in the Park 扫描线

    Walk in the Park 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemi ...

  9. 扫描线 - UVALive - 6864 Strange Antennas

    Strange Antennas Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=87213 M ...

随机推荐

  1. qemu-kvm编译错误

    今天编译了下qemu-kvm,死活编不过,错误信息如下: CC    block/qcow2-snapshot.oIn file included from ./qemu-common.h:6:0,  ...

  2. javascript点滴积累

    1. javascript中的array, set, map 均为数据容器,使用iterable内置的forEach方法 var a = ['A', 'B', 'C'];a.forEach(funct ...

  3. 九度OJ 1114:神奇的口袋 (DFS、DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:948 解决:554 题目描述: 有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40.John现在有n个 ...

  4. Windows平台,开机自动运行应用

    打开注册表编辑器(Win+R后执行regedit) 进入HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 新建字符串值, ...

  5. DIV+CSS常见问题的14条原因分析

    当你在一个浏览器里面做好,在其他浏览器里面却完全不是那么回事情.  很多时候,我们就只是去修补下,或者利用各个浏览器对代码支持的不一致,进行针对各个浏览器进行不同的定义.  其实浏览器的不兼容,我们往 ...

  6. Ace(二)Demo示例

    Client: #include "ace/Log_Msg.h" #include "ace/OS.h" #include "ace/Service_ ...

  7. /dev/sda2 is mounted; will not make a filesystem here!

    一定要记住,不可以在分区挂载之后再进行格式化!!在错误提示当中可以看出你的分区已经挂载了.先将这个分区卸载了再重新格式化:umount /dev/sda2mkfs.ext2 /dev/sda2这样就没 ...

  8. [RK3288][Android6.0] 调试笔记 --- 移除uboot和kernel开机logo【转】

    本文转载自:http://blog.csdn.net/kris_fei/article/details/71600690 Platform: RockchipOS: Android 6.0Kernel ...

  9. Sublime Text 快捷键及使用技巧的学习整理

    下载和安装(很简单,省略)下载地址 http://www.sublimetext.com/2 1. 有两点需要注意 a) Sublime Text目前稳定的版本是Sublime Text 2,Subl ...

  10. 值域线段树 (玲珑OJ 1117)

    点击打开题目链接 题目意思很简单: 1.插入x 2.把小于x的数变成x 3.把大于x的数变成x 4.求集合中第x小数 5.求集合中小于x的数个数 思路: 线段树,节点是值的分数,你可以离散,也可以不离 ...