poj Labeling Balls 3687 拓扑排序!!!!
来源:互联网 发布:nvslp监控软件下载 编辑:程序博客网 时间:2024/05/16 17:53
话说这道题 题意我理解的 是真纠结 ,他是 你将 球按照他的要求 放好,而他的要求是 你将球放好后 从一到n编号 这时的编号 来 符合 要求的条件
而偶一开始以为 输出标签的 标签还和重量相等 真是坑爹 其实是按标签从小到大的顺序输出球的重量,题中给的要求也是用标签号表示 的
进入正题
从后向前拓扑使大数数组后面 自然小数在前面 我们在存答案的 也是从小到大
#include<iostream>#include<stdio.h>#include<memory.h>int g[205][205],degree[205],ans[205];using namespace std;int main(){ int n,a,b,m,t; while(cin>>t) { while(t--) { memset(g,0,sizeof(g)); memset(degree,0,sizeof(degree)); scanf("%d%d",&n,&m); while(m--) { scanf("%d%d",&a,&b); if(g[b][a]==0) { g[b][a]=1; degree[a]++; } } int sign=0; for(int i=n;i>=1;i--) { int temp; sign=0; for(int j=n;j>=1;j--) { if(degree[j]==0) { temp=j; sign=1; break; } } if(sign==0)//主要判断没有连成线(没有连成线上面的for循环会执行几次后就不执行了) 或 连成环(一次都不会执行) break; else { degree[temp]--; ans[temp]=i; for(int k=1;k<=n;k++) { if(g[temp][k]!=0) degree[k]--; } } } if(sign==0) printf("-1\n"); else { for(int i=1;i<n;i++) printf("%d ",ans[i]); printf("%d\n",ans[n]); } } } return 0;}
- poj 3687 Labeling Balls(拓扑排序)
- POJ 3687 Labeling Balls 拓扑排序
- poj 3687 【拓扑排序】【Labeling Balls】
- poj Labeling Balls 3687 拓扑排序!!!!
- poj 3687 Labeling Balls 拓扑排序
- POJ 3687Labeling Balls(拓扑排序)
- POJ 3687 Labeling Balls 拓扑排序
- poj 3687 Labeling Balls ( 拓扑排序 )
- Poj 3687 Labeling Balls[拓扑排序]
- Poj 3687 Labeling Balls (拓扑排序)
- poj 3687 Labeling Balls(拓扑排序)
- [POJ 3687] Labeling Balls [拓扑排序]
- POJ 3687 Labeling Balls(拓扑排序)
- poj 3687 Labeling Balls 拓扑排序
- POJ 3687-Labeling Balls(逆序拓扑排序)
- POJ 3687 Labeling Balls 逆向拓扑排序
- poj 3687 Labeling Balls(拓扑排序)
- **poj 3687 Labeling Balls (*拓扑排序)
- UICatalog 随手记
- 学习OpenCV——SVM
- 字符串中字符'\0'是二进制值为零
- 也论全排列的递归实现
- Windows Phone中的路由事件-以ListBox控件为例
- poj Labeling Balls 3687 拓扑排序!!!!
- Dataguard的switchover 和failover 并将老主库flashback 成standby库
- 9省启动IPv6试点
- Silverlight 基础收集
- 配置apache反向代理,解决js跨域问题
- IOS多线程读写Sqlite问题解决
- RAC搭建standby
- NSNotificationCenter消息注册与撤销
- 我的VB作业