例题20 流星(LA 3905)

给你一个矩形,还有n个点初始位置和速度,求矩形内包含流星最多的时刻,注意,矩形的边上不算照到.
模型建立:把t看作一个变量,那么对于每个流星 x x x来说,它在矩形出现的时间可以简化为 [ L x , R x ] [L_x,R_x] [Lx,Rx],那么问题转化为从左边往后边扫求某个时刻,该竖线 t t t与最多区间相交.
注意,要先处理 R x R_x Rx的事件,因为在那一时刻,该流星已经消失看不见了.
观看蓝书代码后,技巧又学到了.因为我们只关注这个区间的左右端点 L X , R x L_X,R_x LX,Rx,只用把他们存进去就行.

/*
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+2;
const int INF = 1e9+7;
typedef pair<int,int> pii;
void update(int x,int a,int w,double &L,double &R){
	if(a==0){
		//该分量没有速度
		if(x<=0||x>=w) R = L - 1;  
	}
	else if(a>0){
		L = max(L,(double)(0-x)/a);//只有x在负半轴才有意义.
		R = min(R,(double)(w-x)/a); 
	}
	else{
		L = max(L,(double)(w-x)/a);
		R = min(R,(double)(0-x)/a);
	}
}
struct Node{
	double dis;int type;
	bool operator < (const Node &rhs) const{
	return dis<rhs.dis || (dis==rhs.dis&&type>rhs.type);}
};
int main(){
//	freopen("1.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		int n,w,h;
		cin>>w>>h>>n;
		vector<Node> vec;
		for(int i=0;i<n;i++){
			int x,y,a,b;
			cin>>x>>y>>a>>b;
			double L=0;double R= INF;
			update(x,a,w,L,R);
			update(y,b,h,L,R);
			if(R>L){
				vec.push_back({R,1});
				vec.push_back({L,0});
			}
		}
		sort(vec.begin(),vec.end());
		int cnt = 0;int ans = 0;
		for(auto it : vec){
			if(it.type==1) cnt--;
			else cnt++,ans=max(cnt,ans);
		}
		cout<<ans<<"\n";
	}
return 0;}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

minato_yukina

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值