LA3211 Now or later

Posted 嘒彼小星

tags:

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

题目大意:n架飞机,每架可选择两个着落时间。安排一个着陆时间表,使得着陆间隔的最小值最大。(转自http://blog.csdn.net/u013514182/article/details/42333363)

 

每个飞机有两个选择:时间1或时间2,分别用xi和x‘表示。最小值最大,考虑二分答案ans;

对于任意两家飞机x,y,x选择时间k,y选择时间l,如果时间差小于ans,说明1、x选k后y必须不能选l,2、y选l后x必须不能选k

边开小了,疯狂RE,边居然要开到千万级别。。。竟然出了这么极端的数据专门卡空间。。。出题人真XX

技术分享图片
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <vector>
 8 #include <map>
 9 #include <string> 
10 #include <cmath> 
11 #define min(a, b) ((a) < (b) ? (a) : (b))
12 #define max(a, b) ((a) > (b) ? (a) : (b))
13 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
14 template<class T>
15 inline void swap(T &a, T &b)
16 {
17     T tmp = a;a = b;b = tmp;
18 }
19 inline void read(int &x)
20 {
21     x = 0;char ch = getchar(), c = ch;
22     while(ch < 0 || ch > 9) c = ch, ch = getchar();
23     while(ch <= 9 && ch >= 0) x = x * 10 + ch - 0, ch = getchar();
24     if(c == -) x = -x;
25 }
26 const int INF = 0x3f3f3f3f;
27 const int MAXN = 50000 + 10;
28 struct Edge
29 {
30     int u,v,nxt;
31     Edge(int _u, int _v, int _nxt){u = _u;v = _v;nxt = _nxt;}
32     Edge(){}
33 }edge[20000000];
34 int head[MAXN], cnt;
35 inline void insert(int a, int b)
36 {
37     edge[++ cnt] = Edge(a, b, head[a]), head[a] = cnt;
38 }
39 int n, t[MAXN][2], dfn[MAXN], dfst, low[MAXN], b[MAXN], bb[MAXN], group, belong[MAXN], stack[MAXN], top;
40 void dfs(int u)
41 {
42     b[u] = bb[u] = 1, stack[++ top] = u, dfn[u] = low[u] = ++ dfst;
43     for(int pos = head[u];pos;pos = edge[pos].nxt)
44     {
45         int v = edge[pos].v;
46         if(!b[v]) dfs(v), low[u] = min(low[v], low[u]);
47         else if(bb[v]) low[u] = min(low[u], dfn[v]);
48     }
49     if(low[u] == dfn[u])
50     {
51         ++ group;
52         int now = -1;
53         while(now != u)    now = stack[top --], belong[now] = group, bb[now] = 0;
54     }
55 }
56 
57 void tarjan()
58 {    
59     dfst = 0, group = 0, memset(belong, 0, sizeof(belong)), memset(dfn, 0, sizeof(dfn)), memset(low, 0, sizeof(low)), memset(b, 0, sizeof(b)), memset(bb, 0, sizeof(bb));
60     for(int i = 1;i <= n;++ i) if(!b[i << 1]) dfs(i << 1);
61     for(int i = 1;i <= n;++ i) if(!b[i << 1 | 1]) dfs(i << 1 | 1);
62 }
63 
64 int check(int m)
65 {
66     memset(head, 0, sizeof(head)), cnt = 0;
67     for(int i = 1;i <= n;++ i)
68         for(int k = 0;k <= 1;++ k)
69             for(int j = i + 1;j <= n;++ j)
70                 for(int l = 0; l <= 1;++ l)    
71                     if(abs(t[i][k] - t[j][l]) < m)
72                         insert(i << 1 | k, j << 1 | (l ^ 1)), insert(j << 1 | l, i << 1 | (k ^ 1));
73     tarjan();
74     for(int i = 1;i <= n;++ i) if(belong[i << 1] == belong[i << 1 | 1]) return 0;
75     return 1;
76 }
77 
78 int main()
79 {
80     while(scanf("%d", &n) != EOF)
81     {
82         int l = 1, r = 0, mid, ans = 0;
83         for(int i = 1;i <= n;++ i) read(t[i][0]), read(t[i][1]), r = max(r, max(t[i][1], t[i][0]));
84         while(l <= r)
85         {
86             mid = (l + r) >> 1;
87             if(check(mid)) l = mid + 1, ans = mid;
88             else r = mid - 1;
89         } 
90         printf("%d\n", ans);
91     }
92     return 0;
93 }
LA3211

 

以上是关于LA3211 Now or later的主要内容,如果未能解决你的问题,请参考以下文章

UVALive 3211 : Now or later (2-SAT)

UVALive3211- Now or later(二分+2-SAT)

UVA11404 Now or later

la3211

LA 3211 飞机调度(2—SAT)

LA3211 训练指南飞机调度 2-sat