数据有点水
查看原帖
数据有点水
556455
AllureLove2410喜欢若彤楼主2022/8/22 20:56

为什么暴力加卡时再加上一个特判就过了

#include<bits/stdc++.h>
using namespace std;
const int xrt=5e4+3;
int L,m,n;
int a[xrt];
int ans;
inline bool zsm(int x){
	int tot=0,now=0,cnt=0;
	while(cnt<m+1){
		cnt++;
		if(a[cnt]-a[now]<x)tot++;
		else now=cnt;
	}
	if(tot>n)return false;
	else return true;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>L>>m>>n;
	for(int i=1;i<=m;i++)
		cin>>a[i];
	if(m==0&&n==0){
	    cout<<L;
        return 0;
	}
	a[m+1]=L;
	int l=1,r=L;
	for(;l<=r;l++){
        if(zsm(l))ans=l;
        if((double)clock()/CLOCKS_PER_SEC>0.9)break;
    }
	cout<<ans<<"\n";
	return 0;
}
2022/8/22 20:56
加载中...