跳到正文

题解

P9784 [ROIR 2020 Day1] 超速 题解

Ame_wiki约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年7月6日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟
获赞
2
题目
P9784

版本

  1. v1当前

题目传送门:link。

思路:一看最大值最小,二分直接秒。二分出在哪个罚款段,因为答案是取最高罚款,所以在每段路都要跑到上限,速度为 vi+amidv_i+a_{mid} 米每秒。车从 ss 时间来到 tt 时间去,花费 t−st-s 时间,只需要将二分出的答案与其比较即可。

二分好难调啊。

code

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

const int N=100005,M=5005,inf=1e18;

int n,m,q,l[N],v[N],a[N],f[N];

int ck(int x,int y){
	double ans=0;
	for(int i=1;i<=n;i++){
		ans+=l[i]*1.0/(x+v[i]);
	}
//	cout<<x<<" "<<y<<": "<<ans<<endl;
	if(ans<=y) return 1;
	else return 0;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>v[i];
	for(int i=1;i<=n;i++) cin>>l[i];
	cin>>m;
	for(int i=1;i<m;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>f[i];
	cin>>q;
	a[m]=inf;
	while(q--){
		int s,t; cin>>s>>t;
		int cha=t-s;
		int ll=0,r=m-1;
		while(ll<r){
			int mid=(ll+r)>>1;
			if(ck(a[mid],cha)) r=mid;
			else ll=mid+1;
		}
		if(!ck(a[ll],cha)) ll++;
		cout<<f[ll]<<endl;
	}
	return 0;
} 
原文