Algorithm: UVa 1146

Source: Internet
Author: User
Tags abs bool int size min time interval

"The main effect of the topic"

There are n planes to land, and each plane can opt for an "early landing" or "late landing", which cannot be landed at any other time. Give each aircraft "early landing" and "play landing" time, asked how to arrange the landing, can make any two aircraft of the land time interval is minimal, output minimum.

Ideas

Water problem, the minimum interval of two minutes, with 2-sat judgment.

Code

#include <iostream> #include <queue> #include <cstdio> #include <cstring> #include <CMATH&G  
T  
    
using namespace Std;  
const int MAXN = 2005;  
const int VN = MAXN*2;  
const int EN = MAXN*MAXN*4;  
int n, m;  
    
int t[maxn][2];  
    struct graph{int size, HEAD[VN]; Struct{int V, next;  
    E[en];  
    void Init () {size=0; memset (Head,-1, sizeof (head));}  
        void Addedge (int u, int v) {e[size].v = v;  
        E[size].next = Head[u];  
    Head[u] = size++;  
    
}}g;  
        Class two_sat{Public:bool Check () {SCC ();  
        for (int i=0; i<n; ++i) if (belong[i] = = Belong[i+n]) return false;  
    return true;  
        } private:void Tarjan (const int u) {int V;  
        Low[u] = dfn[u] = ++idx;  
        Instack[u] = true;  
        sta[top++] = u;  
            for (int e=g.head[u]; E!=-1 e=g.e[e].next) {v = g.e[e].v; IF (dfn[v] = =-1) {Tarjan (v);  
            Low[u] = min (Low[u], low[v]);  
        }else if (Instack[v]) low[u] = min (low[u), dfn[v]);  
            } if (dfn[u] = = Low[u]) {++bcnt;  
                do{v = sta[--top];  
                INSTACK[V] = false;  
            BELONG[V] = bcnt;  
        }while (U!= v);  
        } void SCC () {idx = top = bcnt = 0;  
        memset (instack, 0, sizeof (instack));  
        memset (DFN,-1, sizeof (DFN));  
    for (int i=0; i<2*n; ++i) if (dfn[i] = = 1) tarjan (i);  
    } private:int idx, top, bcnt;  
    int STA[VN], low[vn], DFN[VN], BELONG[VN];  
BOOL INSTACK[VN];  
    
    
}sat;  
    void buildgraph (int minT) {g.init ();  
            for (int i=0; i<n; ++i) {for (int j=i+1; j<n; ++j) {int ta1=t[i][0], ta2=t[i][1];  
   int tb1=t[j][0], tb2=t[j][1]; 
            if (ABS (TA1-TB1) < MinT) {G.addedge (I, j+n);  
            G.addedge (J, I+n);  
                } if (ABS (TA1-TB2) < MinT) {G.addedge (i, j);  
            G.addedge (J+n, i+n);  
                } if (ABS (TA2-TB1) < MinT) {G.addedge (i+n, j+n);  
            G.addedge (J, I);  
                } if (ABS (TA2-TB2) < MinT) {G.addedge (i+n, J);  
            G.addedge (J+n, i); int main () {while (~SCANF ("%d", &n)) {for (int i=0; i <n;  
    
        ++i) scanf ("%d%d", &t[i][0), &t[i][1]);  
        int l=0, R=1e7, Mid, ans=-1;  
            while (L < r) {mid = (l+r) >>1;  
            Buildgraph (mid);  
                if (Sat.check ()) {ans = mid;  
            L = mid+1;  
        }else r = Mid; }  
        printf ("%d\n", ans);  
return 0; }

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.