狗带拓扑
来源:互联网 发布:国外域名交易论坛 编辑:程序博客网 时间:2024/05/01 18:06
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>#include <cmath>#include <map>#include <set>using namespace std;const double pi = 3.14159265358979323846264338327950288419716939937511;const double eps = 1e-8;const int INF = 8000000;const int maxn = 110;bool vis[maxn];int c[maxn],n;int topo[maxn],t;bool G[maxn][maxn];bool dfs(int u){ c[u]=-1;//been visited for(int v=1;v<=n;v++){ if(G[u][v]){ if(c[v]<0){ //cout<<"yuanyuanyuan\n"; return false; }else if(!c[v]&&!dfs(v)){ return false; } } } c[u]=1; topo[t--]=u; return true;}bool topoSort(){ t = n; memset(c, 0, sizeof(c)); for(int u=1;u<=n;u++){ if(!c[u]){ if(!dfs(u)){ //cout<<"wuwuuwuw\n"; return false; } } } return true;}void out(){ int i; for(i=n;i>=1;i--){ cout<<(char)('A'+topo[i]-1); }}int main(){freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); int m; while(scanf("%d%d",&n,&m)&&n){ string in; int i; t = n; //memset(c,0,sizeof(c)); memset(G,0,sizeof(G)); memset(vis,false,sizeof(vis)); bool flag = true; bool possible = true; int determined; int ans = 0; for(i=1;i<=m;i++){ if(ans == n){ flag = false; printf("Sorted sequence determined after %d relations:",i-1); out(); printf(".\n"); ans=INF; } cin>>in; if(flag){ if(vis[in[0]-'A']==false){ ans ++; vis[in[0]-'A'] = true;}if(vis[in[2]-'A']==false){ans++;vis[in[2]-'A'] = true;} if(in[1]=='>'){ G[in[0]-'A'+1][in[2]-'A'+1]=true; }else{ G[in[2]-'A'+1][in[0]-'A'+1]=true; } if(!topoSort()){ possible = false; determined = i; } } } if(!possible){ printf("Inconsistency found after %d relations.\n", determined); continue; } if(ans<n){ printf("Sorted sequence cannot be determined.\n"); continue;} } return 0;}
0 0
- 狗带拓扑
- 拓扑
- 拓扑
- 拓扑
- 拓扑
- 拓扑排序
- 网络拓扑
- 拓扑结构图
- 拓扑排序
- 拓扑排序
- 拓扑排序
- 拓扑排序
- 拓扑序列
- 拓扑排序
- 拓扑排序
- 拓扑排序
- 拓扑排序
- 拓扑排序
- 一天上课
- shell 学习笔记 (二)——环境变量
- 机器学习中,从一张图片中提取出感兴趣的区域(以交通标志为例)
- Java设计模式(行为型)之-迭代器模式
- SPI通讯协议
- 狗带拓扑
- 免费极客学院Vip使用
- 基于Android移动终端的微型餐饮管理系统的设计与实现3-技术整合
- leetcode 5: Longest Palindromic Substring
- plot函数(转)
- 解决php输出中文乱码问题
- hibernate报错总结(持续更新)
- 文件编程函数
- Labeling Balls