Poj3683 (2-set

Source: Internet
Author: User

poj3683

Title: There are several activities that can be selected in one of two time periods, asking for an allocation scheme that makes all activities non-conflicting.

Idea: 2set bare topic, sset need to do a strong unicom component decomposition, and then need to do a topological sequencing, but if the strong Unicom component decomposition using two times DFS, then you can save this step.

/** @author: Cwind*////#pragma COMMENT (linker, "/stack:102400000,102400000")#include <iostream>#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<vector>#include<queue>#include<stack>#include<functional>#include<Set>#include<cmath>using namespacestd;#defineIOS Std::ios::sync_with_stdio (false); Std::cin.tie (0)#definePB Push_back#definePB Pop_back#defineBK Back ()#defineFS First#defineSe Second#defineSq (x) (x) * (x)#defineEPS (3E-7)#defineIinf (1<<29)#defineLinf (1ll<<59)#defineINF (1000000000)#defineFinf (1E3)#defineCLR (x) memset ((x), 0,sizeof (x));typedefLong Longll;typedef unsignedLong LongUll;typedef pair<int,int>Pii;typedef pair<int,int>P;Const intmaxn=2005;intN;inta[maxn][3];Charr[ -];vector<int>G[maxn],rg[maxn],od;BOOLVIS[MAXN];intSCCID[MAXN];int Get(CharACharb) {    return(A-'0')*Ten+b-'0';}BOOLInterintAintBintCintd) {    return! (a>=d| | b<=c);}voidAddedge (intAintb)    {G[A].PB (b); RG[B].PB (a);}voidDFS1 (intv) {Vis[v]=1;  for(intI=0; I<g[v].size (); i++){        intu=G[v][i]; if(!Vis[u]) dfs1 (U); } OD.PB (v);}voidDFS2 (intVintk) {Vis[v]=1; SCCID[V]=K;  for(intI=0; I<rg[v].size (); i++){        intu=Rg[v][i]; if(!Vis[u]) DFS2 (u,k); }}intV;voidSCC () {CLR (VIS); Od.clear ();  for(intI=1; i<=v;i++){        if(!Vis[i]) dfs1 (i);    } CLR (VIS); intId=1;  for(intI=od.size ()-1; i>=0; i--){        intv=Od[i]; if(!vis[v]) DFS2 (v,id++); }}voidbuild () { for(intI=1; i<=n;i++){         for(intj=i+1; j<=n;j++){            if(Inter (a[i][0],a[i][0]+a[i][2],a[j][0],a[j][0]+a[j][2]) {Addedge (i,j+N); Addedge (J,i+N); }            if(Inter (a[i][0],a[i][0]+a[i][2],a[j][1]-a[j][2],a[j][1]) {Addedge (i,j); Addedge (J+n,i+N); }            if(Inter (a[i][1]-a[i][2],a[i][1],a[j][0],a[j][0]+a[j][2]) {Addedge (i+n,j+N);            Addedge (J,i); }            if(Inter (a[i][1]-a[i][2],a[i][1],a[j][1]-a[j][2],a[j][1]) {Addedge (i+n,j); Addedge (J+n,i); }        }    }}BOOLANS[MAXN];intMain () {Freopen ("/home/slyfc/cppfiles/in","R", stdin); //freopen ("defense.in", "R", stdin); //freopen ("Defense.out", "w", stdout);Cin>>N; V=n*2;  for(intI=1; i<=n;i++) {scanf ("%s", R); a[i][0]=Get(r[0],r[1])* -+Get(r[3],r[4]); scanf ("%s", R); a[i][1]=Get(r[0],r[1])* -+Get(r[3],r[4]); scanf ("%d", &a[i][2]);    } build ();    SCC ();  for(intI=1; i<=n;i++){        if(sccid[i]==sccid[i+N]) {Puts ("NO"); return 0; }Else{            if(sccid[i]>sccid[i+N]) {Ans[i]=1; }Else{Ans[i]=0; }}} puts ("YES");  for(intI=1; i<=n;i++){        if(Ans[i]) {ints=a[i][0],t=a[i][0]+a[i][2]; printf ("%02d:%02d%02d:%02d\n", s/ -, s% -, t/ -, t% -); }Else{            ints=a[i][1]-a[i][2],t=a[i][1]; printf ("%02d:%02d%02d:%02d\n", s/ -, s% -, t/ -, t% -); }    }    return 0;}
View Code

Poj3683 (2-set

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.