二分时间+2sat
边加多了....RE了好久......
Now or later
[Submit] [Go Back] [Status] Description 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 Figure 1: A simple Holding Pattern as described in a pilot text book. Jim Tarjan, an air-traffic controller, has asked his brother Robert to help him to improve the behavior of the airport. 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 ( 2n2000). 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 Note: The input file corresponds to Table 1. Robert‘s Hints
And now comes Robert‘s big insight: our problem has a solution, if and only if we have no contradiction. A contradiction being something like Ai ?Ai. |
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=4010; struct Edge { int to,next; }edge[maxn*maxn*4]; int Adj[maxn],Size; void init() { Size=0; memset(Adj,-1,sizeof(Adj)); } void Add_Edge(int u,int v) { edge[Size].to=v; edge[Size].next=Adj[u]; Adj[u]=Size++; } int Low[maxn],DFN[maxn],Instack[maxn],Belong[maxn]; int Index,Stack[maxn],top,scc; void Tarjan(int u) { DFN[u]=Low[u]=++Index; Stack[top++]=u; Instack[u]=1; int v; for(int i=Adj[u];~i;i=edge[i].next) { v=edge[i].to; if(!DFN[v]) { Tarjan(v); Low[u]=min(Low[v],Low[u]); } else if(Instack[v]) { Low[u]=min(Low[u],DFN[v]); } } if(DFN[u]==Low[u]) { scc++; do { v=Stack[--top]; Instack[v]=0; Belong[v]=scc; }while(v!=u); } } bool ck(int n) { memset(DFN,0,sizeof(DFN)); memset(Instack,0,sizeof(Instack)); Index=scc=top=0; for(int i=0;i<n;i++) { if(!DFN[i]) Tarjan(i); } for(int i=0;i<n;i+=2) { if(Belong[i]==Belong[i^1]) return false; } return true; } int air[maxn][2],n; bool test(int mid) { init(); for(int i=0;i<n;i++) { for(int k1=0;k1<2;k1++) { for(int j=i+1;j<n;j++) { for(int k2=0;k2<2;k2++) { if(abs(air[i][k1]-air[j][k2])<mid) { Add_Edge(i*2+k1,j*2+1-k2); Add_Edge(j*2+k2,i*2+1-k1); } } } } } return ck(n*2); } int main() { while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { scanf("%d%d",&air[i][0],&air[i][1]); } int ans=-1,low=0,high=1e7+10,mid; while(low<=high) { mid=(low+high)/2; if(test(mid)) ans=mid,low=mid+1; else high=mid-1; } printf("%d\n",ans); } return 0; }
UVA 1146 Now or later,布布扣,bubuko.com