poj2367(拓扑排序)
来源:互联网 发布:编程器使用方法 编辑:程序博客网 时间:2024/06/05 10:21
题目就是让你求拓扑序
拓扑排序就是,先找到入度为0的点,删去,同时把它的所有出度删去,再找新的入度为0的点,删去的点的顺序就是拓扑序
#include <cstdio> #include <iostream>#include <cstring>#include <algorithm>using namespace std;int s[233][233];int in_degree[2333];int a[2333],n;int out[2333];bool vis[2333];int main(){ scanf("%d",&n); for(int i = 1; i <= n; i ++) { for(int j = 1; ; j ++) { scanf("%d",&a[j]); if(a[j] == 0) break; s[i][a[j]] = 1; in_degree[a[j]]++; } } for(int i = 1; i <= n; i ++) { int t = 0; for(int j = 1; j <= n; j ++) { if(in_degree[j] == 0 && !vis[j]) { vis[j] = 1; t = j; break; } } if(t == 0) break; else out[i] = t; for(int j = 1; j <= n; j ++) { if(s[t][j] == 1) in_degree[j]--; } } for(int i = 1; i <= n; i ++) cout <<out[i]<<" "; return 0;}
2 0
- poj2367 拓扑排序
- POJ2367 拓扑排序入门
- POJ2367(拓扑排序)
- POJ2367拓扑排序入门
- poj2367 拓扑排序
- poj2367 拓扑排序入门
- POJ2367【拓扑排序】
- poj2367(拓扑排序)
- POJ2367 Genealogical tree (拓扑排序)
- 拓扑排序简单应用poj2367
- POJ2367 Genealogical tree(拓扑排序)
- poj2367 Genealogical tree【拓扑排序】
- 简单的拓扑排序(POJ2367)
- poj2367 Genealogical tree 拓扑排序初接触
- (拓扑排序)poj2367,Genealogical tree
- poj2367 Genealogical tree(拓扑排序:输出方案)
- 纯拓扑排序一搞poj2367
- poj2367 Genealogical tree (裸拓扑排序)
- 排序算法(六) 选择排序
- 好了,被百度地图的配置坑了一中午,做个总结吧
- 运用循环输出一个空心的菱形
- 事件(三)
- Android闪光灯实现
- poj2367(拓扑排序)
- 归并排序
- 排序算法(七) 堆排序
- VIM for windows
- JAVA养成计划——每天学一点JAVA
- 关于中文乱码这坑
- 一道常被人轻视的前端JS面试题
- IOS的基本控件的使用-UIViewController基础
- 从0开始学习 GITHUB 系列之「初识 GITHUB」