E.Rescheduling the Exam

Posted thusloop

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E.Rescheduling the Exam相关的知识,希望对你有一定的参考价值。

显然可以二分答案,check里 记录a[i]-a[i-1]-1<x的数量计为nd 计即需要移动的数量
如果nd>=3 则无解
nd =2 这两个需要移动的数要连续
nd=1 去判断是否有可以移动到的位置
nd=0 一定可以
(有一点细节

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=8e18;
const int maxn=2e5+100;
int a[maxn];
bool pd[maxn];
int n,d;
bool ck(int x)

	for(int i=1; i<=n; i++) pd[i]=0;
	bool fg=0;
	int nd=0;
	if(a[1]-1<x)
	
		nd++;
		pd[1]=1;
	
	if(a[1]-1>2*x)fg=1;
	for(int i=2; i<=n; i++)
	
		if(a[i]-a[i-1]-1<x)
		
			pd[i]=1;
			nd++;
		
		if(a[i]-a[i-1]-1>2*x) fg=1;
	
	if(a[n+1]-a[n]-1>=x)fg=1;
	if(nd>2)return 0;
	if(nd==0) return 1;
	if(nd==1&&fg)return 1;
	if(nd==1)
	
		int pos;
		for(int i=1; i<=n; i++)
		
			if(pd[i])
			
if(i==n&&a[i]-a[i-2]-1>2*x)return 1;
if(i==n&&a[n+1]-a[n-1]-1>=x)return 1;
				if(i-2>=0&&a[i]-a[i-2]-1>2*x)return 1;
				if(a[i+1]-a[i-1]-1>2*x)return 1;
				//if(i+2<=n+1&&a[i+2]-a[i]-1>2*x)return 1;
				return 0;
			
		
	
	bool fg2=0;
	int pos=-1;
	for(int i=2; i<=n; i++)
	
		if(pd[i]&&pd[i-1])
		
			fg2=1;
			pos=i-1;
		
	
	if(pos!=-1&&a[pos+1]-a[pos-1]-1<x)return 0;
	if(fg2==0)return 0;
	if(fg)return 1;
if(pos!=-1&&a[pos+1]-a[pos-1]-1>2*x)return 1;
	return 0;

signed main()

	IOS
	int tt;
	cin>>tt;
	while(tt--)
	
		cin>>n>>d;
		for(int i=1; i<=n; i++)
		
			cin>>a[i];
		
		a[n+1]=d;
		int l=0,r=(int)1e10;
		//cout<<ck(5)<<"\\n";
		while(l<=r)
		
			int mid=(l+r)>>1;
			if(ck(mid))l=mid+1;
			else r=mid-1;
		
 cout<<r<<"\\n";
	

以上是关于E.Rescheduling the Exam的主要内容,如果未能解决你的问题,请参考以下文章

The Best CLOUDF Exam Cram Ever - Pass Easily CLOUDF Exam

The Best GCIH Exam Cram Ever - Pass Easily GCIH Exam

The Best 500-901 Exam Cram Ever - Pass Easily 500 901 Exam

The Best 700-280 Exam Cram Ever - Pass Easily 700 280 Exam

The Best 700-551 Exam Cram Ever - Pass Easily 700 551 Exam

The Best PR2F Exam Cram Ever - Pass Easily PR2F Exam