【扫描法】Meteor UVALive - 3905
传送门:
https://vjudge.net/problem/UVALive-3905
分析
将每个点进出矩形的时间的左右区间 处理出来,这样就可以在一维的时间轴做扫描法了。
细节&技巧:
-
注意到在矩形边界的点不计入贡献,因此处理出来的时间区间均为开区间,在维护贡献 之前的排序中,在时间点相等的时候,指定出队的点优先级更高以使贡献被正确维护。
-
在
update
操作中出现了除数运算,如果需要避免使用double
,可以利用所有可能出现的速度的最小公倍数 。注意到题目中速度的范围在 ,因此 。只需将时间乘上 即可避免使用double
。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb push_back
#define eb emplace_back
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
using pii = pair<int, int>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vpii = vector<pii>;
using ll = long long;
using ull = unsigned long long;
#define int ll
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=1e5+5, D=2520;
int w, h;
int n;
struct Event{
int x, type;
bool operator < (const Event &o)const{
return x==o.x? type<o.type: x<o.x;
}
}e[N<<1];
int tot;
void update(int x, int v, int p, int &L, int &R){
if(v==0){
if(x<=0 || x>=p) L=INF, R=-INF;
}
else if(v>0) L=max(L, -x*D/v), R=min(R, (p-x)*D/v);
else L=max(L, (x-p)*D/-v), R=min(R, x*D/-v);
}
signed main(){
int T; cin>>T;
while(T--){
read(w), read(h);
read(n);
tot=0;
rep(i,1,n){
int x, y, a, b; read(x), read(y), read(a), read(b);
int L=0, R=INF; // time of in and out
update(x, a, w, L, R); // x axis of in and out
update(y, b, h, L, R); // y axis of in and out
if(L<R) e[++tot]={L, 1}, e[++tot]={R, -1};
}
sort(e+1, e+1+tot);
int res=0, cnt=0;
rep(i,1,tot){
cnt+=e[i].type;
res=max(res, cnt);
}
cout<<res<<endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】