UVA 1146 Now or later

The Terminal Radar Approach CONtrol (TRACON) controls aircraft approaching and departing
when they are between 5 and 50 miles of the airport. In this final scheduling process, air traffic
controllers make some aircraft wait before landing. Unfortunately this “waiting” process is complex
as aircraft follow predetermined routes and their speed cannot be changed. To reach some degree of
flexibility in the process, the basic delaying procedure is to make aircraft follow a holding pattern that
has been designed for the TRACON area. Such patterns generate a constant prescribed delay for an
aircraft (see Figure 1 for an example). Several holding patterns may exist in the same TRACON.
In the following, we assume that there is a single runway and that when an aircraft enters the
TRACON area, it is assigned an early landing time, a late landing time and a possible holding pattern.
The early landing time corresponds to the situation where the aircraft does not wait and lands as
soon as possible. The late landing time corresponds to the situation where the aircraft waits in the
prescribed holding pattern and then lands at that time. We assume that an aircraft enters at most
one holding pattern. Hence, the early and late landing times are the only two possible times for the
landing.
The security gap is the minimal elapsed time between consecutive landings. The objective is to
maximize the security gap. Robert believes that you can help.

题目大意:每架飞机可以选择早起飞和晚起飞,早起飞和晚起飞都有一个时间点,求一个安排方案,使得起飞时间的距离的最小值最大

对于最小值最大,显然二分答案,然后我们对于矛盾的建边,跑2-SAT即可

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=4005,M=16000005;
int gi(){
	int str=0;char ch=getchar();
	while(ch>'9' || ch<'0')ch=getchar();
	while(ch>='0' && ch<='9')str=(str<<1)+(str<<3)+ch-48,ch=getchar();
	return str;
}
int n,L[N],R[N],num=0,head[N],to[M],nxt[M];bool mark[N];
void init(int x,int y,bool tx,bool ty){
	x=((x-1)<<1)+tx;y=((y-1)<<1)+ty;
	nxt[++num]=head[x];to[num]=y;head[x]=num;
}
void Clear(){
	memset(head,0,sizeof(head));num=0;
	memset(mark,0,sizeof(mark));
}
int st[N],top=0;
bool dfs(int x){
	if(mark[x])return true;
	if(mark[x^1])return false;
	mark[x]=true;st[++top]=x;
	for(int i=head[x];i;i=nxt[i])
		if(!dfs(to[i]))return false;
	return true;
}
bool solve(){
	int lim=(n<<1);
	for(int i=0;i<lim;i+=2){
		top=0;
		if(!dfs(i)){
			while(top)mark[st[top--]]=false;
			if(!dfs(i^1))return false;
		}
	}
	return true;
}
bool check(int mid){
	Clear();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			if(abs(L[i]-L[j])<mid)init(i,j,0,1);
			if(abs(L[i]-R[j])<mid)init(i,j,0,0);
			if(abs(R[i]-L[j])<mid)init(i,j,1,1);
			if(abs(R[i]-R[j])<mid)init(i,j,1,0);
		}
	}
	return solve();
}
void work()
{
	for(int i=1;i<=n;i++){
		L[i]=gi();R[i]=gi();
	}
	int l=0,r=1e7,mid,ans;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
}

int main()
{
	while(~scanf("%d",&n))work();
	return 0;
}
posted @ 2017-09-05 10:00  PIPIBoss  阅读(124)  评论(0编辑  收藏  举报