LA 3905 Meteor
给出一些点的初始位置(x, y)及速度(a, b)和一个矩形框,求能同时出现在矩形框内部的点数的最大值。
把每个点进出矩形的时刻分别看做一个事件,则每个点可能对应两个事件,进入事件和离开事件。
按这些事件的发生时间进行排序,然后逐个扫描,遇到进入事件cnt++,遇到离开事件--cnt,用ans记录cnt的最大值。
对时间相同情况的处理,当一个进入事件的时刻和离开事件的时刻相同时,应该先处理离开事件后处理进入事件。
因为速度(a, b)是-10~10的整数,所以乘以LCM(1,2,3,,,10) = 2520,可避免浮点数的运算。
后来我还在纳闷t≥0的条件是如何限制的,后来明白因为L的初值为0,所以max(L, t)是不会出现负数的情况的。
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
const int LCM = ; struct Event
{
int x;
int type;
bool operator < (const Event a) const
{
return x < a.x || (x == a.x && type > a.type);
}
}events[maxn * ]; void update(int x, int a, int w, int &L, int &R)
{//0<x+at<w
if(a == )
{
if(x <= || x >= w)
R = L - ;
}
else if(a > )
{
L = max(L, -x*LCM/a);
R = min(R, (w-x)*LCM/a);
}
else
{
L = max(L, (w-x)*LCM/a);
R = min(R, -x*LCM/a);
}
} int main(void)
{
#ifdef LOCAL
freopen("3905in.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int w, h, n, e = ;
scanf("%d%d%d", &w, &h, &n);
for(int i = ; i < n; ++i)
{
int x, y, a, b;
scanf("%d%d%d%d", &x, &y, &a, &b);
int L = , R = (int)1e9;
update(x, a, w, L, R);
update(y, b, h, L ,R);
if(L < R)
{
events[e].x = L; //左端点事件
events[e++].type = ;
events[e].x = R;
events[e++].type = ;
}
}
sort(events, events + e);
int cnt = , ans = ;
for(int i = ; i < e; ++i)
{
if(events[i].type == )
ans = max(ans, ++cnt);
else
--cnt;
}
printf("%d\n", ans);
}
return ;
}
代码君
LA 3905 Meteor的更多相关文章
- LA 3905 Meteor 扫描线
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- 3905 - Meteor
The famous Korean internet company nhn has provided an internet-based photo service which allows The ...
- 【UVALive】3905 Meteor(扫描线)
题目 传送门:QWQ 分析 扫描线搞一搞. 按左端点排序,左端点相同时按右端点排序. 如果是左端点就$ cnt++ $,否则$ cnt-- $ 统计一下$ Max $就行了 代码 #include & ...
- UVaLive 3905 Meteor (扫描线)
题意:给定上一个矩形照相机和 n 个流星,问你照相机最多能拍到多少个流星. 析:直接看,似乎很难解决,我们换一个思路,我们认为流星的轨迹就没有用的,我们可以记录每个流星每个流星在照相机中出现的时间段, ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 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 ...
- 【译】Meteor 新手教程:在排行榜上添加新特性
原文:http://danneu.com/posts/6-meteor-tutorial-for-fellow-noobs-adding-features-to-the-leaderboard-dem ...
- Using View and Data API with Meteor
By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing f ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
随机推荐
- 简单CSS hack:区分IE6、IE7、IE8、Firefox、Opera
一.跨浏览器的网页设计一直是让人很头疼的问题,这不只是因为浏览器的版本众多,还有一个重要的原因是相同浏览器的不同时期的版本也会有差异,甚至是在不同操作同台上还会有不同.因此使CSS hack技术进行浏 ...
- Level2行情和传统行情的区别
序号 Level2行情 传统行情 Level 2特点 Level 2行情优势 1 每3秒钟发送一次行情信息 每6秒钟发送一次 行情显示速度更快 投资者更及时地获得交易信息 2 证券逐笔成交明细信息 证 ...
- 小圣求职记B:总集篇
1. 搜狐sohu 搜狐在正式招聘前邀请了部分应聘者到武汉研发中心开座谈会(因此简历尽量早投,机会多些),有研发的也有产品的,40人左右,座谈会期间介绍了搜狐汽车.北京研发中心.武汉研发中心和搜狐媒体 ...
- poj 2723
Get Luffy Out Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7295 Accepted: 2778 Des ...
- Activity学习(二)——生命周期
一.什么是Activity? 简单的说:Activity就是布满整个窗口或者悬浮于其他窗口上的交互界面.在一个应用程序中通常由多个Activity构成,都会在Manifest.xml中指定一个主的Ac ...
- 《Thinking in C++》学习笔记(一)【第二章】
第二章 对象的创建与使用 2.1语言的翻译过程 翻译器分为两类:解释器(interpreter)和编译器(compiler). 2.1.1解释器 解释器将源代码转化成一些动作(它可由许多机器指令组成) ...
- hdu 3118(二进制枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边, ...
- VS输入法问题
问题描述:启动VS,打开Winform等的界面设计,无法为控件输入中文,另外,运行程序,无法在TextBox等控件中输入中文: 本人的系统环境:Win7旗舰版,VS2008.VS2010和VS2012 ...
- C#中毫米与像素的换算方法
C#中以像素作为尺寸单位,像素是一种相对的尺寸概念,与毫米的转换与当前显示器的分辨率有关.在不同分辨率下转换的系数不同. 借助GDI可以完成毫米至像素的转换. public static double ...
- xml bug之cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration...
1.今天重装了一下MyEclipse7.5,打开原来的Flex项目,又报了以下两个错误,之前解决过,但不想又出现,于是把它的解决方法贴出来,做个备忘! 错误信息为 错误信息 写道 cvc-comple ...