ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【扫描法】Meteor UVALive - 3905

2021-08-20 12:32:30  阅读:160  来源: 互联网

标签:vector 3905 ch read long int UVALive Meteor using


传送门:
https://vjudge.net/problem/UVALive-3905

分析

将每个点进出矩形的时间的左右区间 \([L, R]\) 处理出来,这样就可以在一维的时间轴做扫描法了。

细节&技巧:

  1. 注意到在矩形边界的点不计入贡献,因此处理出来的时间区间均为开区间,在维护贡献 \(cnt\) 之前的排序中,在时间点相等的时候,指定出队的点优先级更高以使贡献被正确维护。

  2. update 操作中出现了除数运算,如果需要避免使用 double,可以利用所有可能出现的速度的最小公倍数 \(lcm\)。注意到题目中速度的范围在 \([1,10]\),因此 \(lcm=2520\)。只需将时间乘上 \(lcm\) 即可避免使用 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;
}

标签:vector,3905,ch,read,long,int,UVALive,Meteor,using
来源: https://www.cnblogs.com/Tenshi/p/15165976.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有