LA3211--Now or later(2-sat)

本文探讨了如何通过二分法结合2-SAT算法优化航班在机场跑道的着陆调度问题,旨在最大化相邻航班间的最小安全间隔。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As you must have experienced, instead of landing immediately, an aircraft sometimes waits in a holding loop close to the runway. This holding mechanism is required by air traffic controllers to space apart aircraft as much as possible on the runway (while keeping delays low). It is formally defined as a ``holding pattern'' and is a predetermined maneuver designed to keep an aircraft within a specified airspace (see Figure 1 for an example).

Figure 1: A simple Holding Pattern as described in a pilot text book.


\epsfbox{p3211.eps}

Jim Tarjan, an air-traffic controller, has asked his brother Robert to help him to improve the behavior of the airport.

The TRACON area 

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.

Example 

Assume there are 10 aircraft in the TRACON area. Table 1 provides the corresponding early and late landing times (columns ``Early'' and ``Late'').


Table 1: A 10 aircraft instance of the problem.


AircraftEarlyLateSolution
A144156Early
A2153182Early
A348109Late
A4160201Late
A555186Late
A654207Early
A755165Late
A81758Early
A9132160Early
A1087197Early


The maximal security gap is 10 and the corresponding solution is reported in Table 1 (column ``Solution''). In this solution, the aircraft land in the following order: A8A1A6A10A3A9A2A7A5A4. The security gap is realized by aircraft A1 and A6.

Input 

The input file, that contains all the relevant data, contains several test cases

Each test case is described in the following way. The first line contains the number n of aircraft ( 2$ \le$n$ \le$2000). This line is followed by n lines. Each of these lines contains two integers, which represent the early landing time and the late landing time of an aircraft. Note that all times t are such that 0$ \le$t$ \le$107.

Output 

For each input case, your program has to write a line that conttains the maximal security gap between consecutive landings.

Sample Input 

 
10
44 156
153 182
48 109
160 201
55 186
54 207
55 165
17 58
132 160
87 197

Sample Output 

 
10
题意:有n架飞机需要着陆,每架飞机可以选择早着陆和晚着陆两种方式之一,且必须选择一种。安排飞机的着陆方式,使得整个着陆计划尽量安全。即相邻两个着陆时间间隔的最小值应该最大。
思路:二分间隔,然后就是2-SAT模板题了。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
#define maxn 4080
#define maxm 16000080
int first[maxn];
int vv[maxm],nxt[maxm],S[maxm];
int e,c,n;
bool vis[maxn];
int T[maxn][2];
void AddEdge(int u,int v)
{
	vv[e] = v;	nxt[e] = first[u];	first[u] = e++;
}

bool dfs(int u)//现在要将u置1
{
	if(vis[u^1])	return 0;
	if(vis[u])	return 1;
	vis[u] = 1;
	S[c++] = u;
	for(int i = first[u];i != -1;i = nxt[i])
	{
		int v = vv[i];
		if(!dfs(v))	return false;
	}
	return true;
}

bool Judge()
{
	for(int i = 0;i < n*2;i+=2)
	{
		if(!vis[i] && !vis[i+1])
		{
			c = 0;
			if(!dfs(i))
			{
				while(c > 0)	vis[S[--c]] = 0;
				if(!dfs(i+1))	return false;
			}
		}
	}
	return true;
}

void init(int mid)
{
	memset(first,-1,sizeof(first));
	memset(vis,0,sizeof(vis));
	e = 0;
	for(int i = 0;i < n;i++)
		for(int a = 0;a < 2;a++)
			for(int j = i+1;j < n;j++)
				for(int b = 0;b < 2;b++)
					if(abs(T[i][a] - T[j][b]) < mid)
					{
						AddEdge(i*2+a,j*2+(b^1));
						AddEdge(j*2+b,i*2+(a^1));
					}
}
int main()
{
	//freopen("in.txt","r",stdin);
	while(scanf("%d",&n)!=EOF && n)
	{
		int l = 0,r = 0;
		for(int i = 0;i < n;i++)
		{
			scanf("%d%d",&T[i][0],&T[i][1]);
			r = max(r,T[i][1]);
			r = max(r,T[i][0]);
		}
		int ans = 0;
		while(l <= r)
		{
			int mid = (l+r) >> 1;
			init(mid);
			if(Judge())
			{
				ans = mid;
				l = mid + 1;
			}
			else r = mid-1;
		}
		printf("%d\n",ans);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值