zoukankan      html  css  js  c++  java
  • poj3683 Priest John's Busiest Day

    不用topsort的,我也不知道为啥。

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    struct Node{
    	int fro, too;
    }nd[2005];
    struct Edge{
    	int too, nxt, val;
    }edge[4000005];
    int uu, vv, ww, n, hea[2005], cnt, dfn[2005], loo[2005], scc, bel[2005];
    int sta[2005], din, ind;
    bool ins[2005];
    bool pd(int x, int y){
    	if(nd[x].fro<=nd[y].fro && nd[x].too>nd[y].fro)	return true;
    	swap(x, y);
    	if(nd[x].fro<=nd[y].fro && nd[x].too>nd[y].fro)	return true;
    	return false;
    }
    void add_edge(int fro, int too){
    	edge[++cnt].nxt = hea[fro];
    	edge[cnt].too = too;
    	hea[fro] = cnt;
    }
    void tarjan(int u){
    	dfn[u] = loo[u] = ++ind;
    	sta[++din] = u;
    	ins[u] = true;
    	for(int i=hea[u]; i; i=edge[i].nxt){
    		int t=edge[i].too;
    		if(!dfn[t]){
    			tarjan(t);
    			loo[u] = min(loo[u], loo[t]);
    		}
    		else if(ins[t])	loo[u] = min(loo[u], dfn[t]);
    	}
    	int j;
    	if(dfn[u]==loo[u]){
    		scc++;
    		do{
    			j = sta[din--];
    			ins[j] = false;
    			bel[j] = scc;
    		}while(dfn[j]!=loo[j]);
    	}
    }
    int main(){
    	cin>>n;
    	for(int i=0; i<n; i++){
    		scanf("%d:%d", &uu, &vv);
    		uu = uu * 60 + vv;
    		scanf("%d:%d", &vv, &ww);
    		vv = vv * 60 + ww;
    		scanf("%d", &ww);
    		nd[2*i].fro = uu, nd[2*i].too = uu + ww;
    		nd[2*i+1].fro = vv - ww, nd[2*i+1].too = vv;
    	}
    	for(int i=0; i<n+n; i++)
    		for(int j=i+1; j<n+n; j++)
    			if(pd(i, j)){
    				add_edge(i, j^1);
    				add_edge(j, i^1);
    			}
    	for(int i=0; i<n+n; i++)
    		if(!dfn[i])
    			tarjan(i);
    	for(int i=0; i<n+n; i+=2)
    		if(bel[i]==bel[i^1]){//说明以前有要求既不能选i又不能选i^1
    			printf("NO
    ");
    			return 0;
    		}
    	printf("YES
    ");
    	for(int i=0; i<n+n; i+=2){
    		int id=bel[i]<bel[i^1]?i:i+1;//为什么要这样做?id小说明先求出来,在图里是靠近下游的,影响小
    		printf("%02d:%02d %02d:%02d
    ", nd[id].fro/60, nd[id].fro%60, nd[id].too/60, nd[id].too%60);
    	}
    	return 0;
    }
    
  • 相关阅读:
    遍历系统进程
    AS3.0实现图像的扭曲
    CMainFrame, View, Doc, App之间的组织
    进程的创建
    自定义异常
    VC6.0快捷键(转载)
    WinMain与应用程序类之间的联系
    解决在Chrome下无法获取showModalDialog返回值的问题
    用js编解码base64
    根据一个绝对路径获取相对路径的方法
  • 原文地址:https://www.cnblogs.com/poorpool/p/8006997.html
Copyright © 2011-2022 走看看