九度 题目1449:确定比赛名次
来源:互联网 发布:微盘交易软件 编辑:程序博客网 时间:2024/05/20 07:58
很明显的拓扑排序问题,绘制成图之后会发现很好理解,刚开始我自己也不是很理解,画图之后思路特别清晰
转载请注明本文地址http://blog.csdn.net/yangnanhai93/article/details/41226221
题目链接http://ac.jobdu.com/problem.php?pid=1449
#include <iostream>#include <memory.h>#include <queue>using namespace std;int A[501],MapCount[501][501];void TopoSort(int n){ priority_queue<int,vector<int>,greater<int> > qu; vector<int>result; for(int i=1;i<=n;i++) if(A[i]==0) qu.push(i); int count=0; while(!qu.empty()) { int front=qu.top(); qu.pop(); result.push_back(front); count++; for (int i=1;i<=n;i++) { if(MapCount[front][i]) { A[i]--; if(A[i]==0) qu.push(i); } } } cout<<result[0]; for (int i=1;i<result.size();i++) { cout<<" "<<result[i]; } cout<<endl;}int main(){ //freopen("data.in","r",stdin); int m,n,x,y; while(cin>>m>>n&&m) { memset(A,0,sizeof(A)); memset(MapCount,0,sizeof(MapCount)); for(int i=0;i<n;i++) { cin>>x>>y; MapCount[x][y]=1; } for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) if(MapCount[i][j]!=0) A[j]++; TopoSort(m); } return 0;}/************************************************************** Problem: 1449 User: vincent_ynh Language: C++ Result: Accepted Time:30 ms Memory:2500 kb****************************************************************/
0 0
- 九度题目1449:确定比赛名次
- 九度题目1449:确定比赛名次
- 九度 题目1449:确定比赛名次
- 九度 题目1449:确定比赛名次
- 九度 题目1449:确定比赛名次
- 九度oj 题目1449:确定比赛名次
- 九度OJ 1449 确定比赛名次
- 九度 OJ 1449 确定比赛名次
- 九度OJ-1449:确定比赛名次
- 题目1449:确定比赛名次
- 题目1449:确定比赛名次
- 题目1449:确定比赛名次
- 九度1449:确定比赛名次(拓扑排序)
- Jobdu 题目1449:确定比赛名次
- 题目81:确定比赛名次
- 确定比赛名次
- 确定比赛名次
- 确定比赛名次
- Java&&RTTI(运行时类型识别)
- Android - Error:Calling startActivity() from outside of an activity context
- C学习笔记——打开文件,并保存错误信息
- 使用left join造成的数据重复问
- 函数指针实现对象传递消息(回调)
- 九度 题目1449:确定比赛名次
- Unity3D学习之第四天(脚本入门)
- 关于struts2加载xml失败的处理
- Android项目之HomeHealth基础学习1:Baseadapter
- .net中XML的详细解析
- Android_3 事件响应
- POJ 1661 hlep Jimmy 题解
- wordpress模板插件收集
- 九度 题目1448:Legal or Not