LA3905 Meteor
2024-09-06 12:22:36
https://vjudge.net/problem/UVALive-3905
计算出每个点在相框中的时间段,扫描线做即可
关键在如何快速计算每个点在相框中的时间段。对每个点进行运动分解,进入的时间L是x进入和y进入的最大,退出时间R是x退出和y退出的最小,画图看一下即可
画图同时可以发现不经过相框的时候会导致L >= R
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(int &a, int &b)
{
int tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const int INF = 0x3f3f3f3f;
const int MAXN = + ; int tt,w,h,n,x[MAXN],y[MAXN],a[MAXN],b[MAXN],flag[MAXN << ], cnt[MAXN << ], tot, t[MAXN << ], ans, tag; bool cmp(int a, int b)
{
return t[a] == t[b] ? flag[a] > flag[b] : t[a] < t[b];
} inline void update(int x, int a, int w, int &L, int &R)
{
if(a == )
{
if(x <= || x >= w) R = L - ;
}
else if(a > )
{
L = max(L, -x * / a);
R = min(R, (w - x) * / a);
}
else
{
L = max(L, (w - x) * / a);
R = min(R, -x * / a);
}
} int main()
{
read(tt);
for(;tt;--tt)
{
read(w), read(h), read(n);
for(register int i = ;i <= n;++ i) read(x[i]), read(y[i]), read(a[i]), read(b[i]);
tot = ;
for(register int i = ;i <= n;++ i)
{
int L = , R = INF;
update(x[i], a[i], w, L, R);
update(y[i], b[i], h, L, R);
if(L < R)
{
t[++tot] = L;flag[tot] = ;cnt[tot] = tot;
t[++tot] = R;flag[tot] = ;cnt[tot] = tot;
}
}
std::sort(cnt + , cnt + + tot, cmp);
ans = tag = ;
for(register int i = ;i <= tot;++ i)
{
if(flag[cnt[i]]) -- tag;
else ++ tag;
ans = max(ans, tag);
}
printf("%d\n", ans);
}
return ;
}
LA3905
最新文章
- Bzoj3041 水叮当的舞步
- js计算字符串出现个数
- 在Linux(Ubuntu)下搭建ASP.NET Core环境并运行 继续跨平台
- [原创]VM虚拟机安装centos6.4详细图文教程
- liunx下tomcat启动报错
- Android 使用MediaStore.Images和 Cursor查询本地图片和图片缩略图
- Scrapy的shell命令(转)
- SQLite for xamarin
- premake Ubuntu下的安装
- C++实现动态顺序表
- links
- 【quickhybrid】JSBridge的实现
- 框架页面高度自动刷新Javascript脚本
- 使用Ninject的一般步骤
- npm那些事儿
- [转]vnpy乱乱谈 02架构
- 【转】vector中erase()的使用注意事项
- JavaScript之this,call,apply
- tomcat8 tomcat-users相关配置
- mysql 数据库备份的多种方式