zoj 1060 Sorting It All Out(拓扑排序)
来源:互联网 发布:sql语句修改字段 编辑:程序博客网 时间:2024/06/09 21:57
#include<bits/stdc++.h>using namespace std;vector< vector<char> >v;int n,m,use[30],cnt[30];char ans[30],s[10];int topsort(int x){ int i,j,t[30],f=1,r,c; memset(ans,0,sizeof(ans)); for(i=0; i<30; i++) t[i]=cnt[i]; c=0; r=0; while(x--) { c=0; for(i=0; i<n; i++) { if(t[i]==0) { j=i; c++; } } if(c>=1) { if(c>1) f=0; for(i=0; i<v[j].size(); i++) { t[v[j][i]]--; } ans[r++]=j+'A'; t[j]=-1; ans[r]=0; } else if(c==0) return -1; } if(f) return r; else return 0;}int main(){ int flag,i,num,ok,k; while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; v.clear(); v.resize(n); memset(use,0,sizeof(use)); memset(cnt,0,sizeof(cnt)); ok=0; num=0; for(i=0; i<m; i++) { scanf("%s",s); cnt[s[2]-'A']++; v[s[0]-'A'].push_back(s[2]-'A'); if(!use[s[0]-'A']) { num++; use[s[0]-'A']=1; } if(!use[s[2]-'A']) { num++; use[s[2]-'A']=1; } if(ok==0) { int t=topsort(num); if(t==n) { ok=1; k=i+1; } else if(t==-1) { ok=-1; k=i+1; } } } if(!ok) printf("Sorted sequence cannot be determined.\n"); else if(ok==1) printf("Sorted sequence determined after %d relations: %s.\n",k,ans); else printf("Inconsistency found after %d relations.\n",k); } return 0;}
0 0
- zoj 1060 || poj 1094 Sorting It All Out(拓扑排序)
- ZOJ 1060 Sorting It All Out (POJ1094) (拓扑排序)
- ZOJ 1060 Sorting It All Out 拓扑排序
- zoj 1060 Sorting It All Out(拓扑排序)
- zoj 1060 Sorting It All Out(拓扑排序)
- POJ 1094 && ZOJ 1060 Sorting It All Out 【拓扑排序入门】
- ZOJ 1060 poj 1094 Sorting It All Out(拓扑排序或 弗洛德)
- poj1094 Sorting It All Out (拓扑排序)
- Poj1094 Sorting It All Out (拓扑排序)
- POJ1094-Sorting It All Out 拓扑排序
- 拓扑排序Sorting It All Out
- poj1094 Sorting It All Out(拓扑排序)
- POJ1094 Sorting It All Out 拓扑排序
- POJ1094 Sorting It All Out(拓扑排序)
- nyoj349 Sorting It All Out(拓扑排序)
- POJ1094 Sorting It All Out(拓扑排序)
- NYOJ_349 Sorting It All Out 拓扑排序
- poj1094 Sorting It All Out (拓扑排序)
- MYSQL连接方式
- HDU 5289 思路+线段树处理
- Weblogic启动报错
- HDU-4552-怪盗基德的挑战书
- ARM寄存器介绍
- zoj 1060 Sorting It All Out(拓扑排序)
- leetCode 82.Remove Duplicates from Sorted List II (删除排序链表的重复II) 解题思路和方法
- Dynamics CRM2015 非基础语言环境下产品无法新建的问题
- Android如何设置圆角按钮
- android <viewStub />, <requestFocus />, <merge /> and <include />用法
- Codeforces Round #279 (Div. 2) B. Queue 模拟
- 初学者很实用:纯struts框架实现用户登陆
- android代码创建布局
- HTMLParser 学习篇上