uva 10305 - Ordering Tasks
来源:互联网 发布:斑马打印机软件下载 编辑:程序博客网 时间:2024/05/17 01:10
Problem F
Ordering Tasks
Input: standard input
Output: standard output
Time Limit:1 second
Memory Limit:32 MB
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed.
Input
The input will consist of several instances of the problem. Each instance begins with a line containing two integers,1 <= n <= 100 and m. n is the number of tasks (numbered from 1 to n) and m is the number of direct precedence relations between tasks. After this, there will bem lines with two integers i andj, representing the fact that task i must be executed before taskj. An instance with n = m = 0 will finish the input.
Output
For each instance, print a line with n integers representing the tasks in a possible order of execution.
Sample Input
5 4
1 2
2 3
1 3
1 5
0 0
Sample Output
1 4 2 5 3
拓扑排序,每次找入度为0的点,删除相关边然后重复操作。
#include<stdio.h>int n,step,a[101][101],visit[101];int sort(){int i,x=0,y,f=1; if (step<=0) return 0; --step; while (f) {++x; y=0; if (visit[x]) { for (i=1;i<=n;i++) {y=y+a[i][x]; if (y>0) break; } f=y; } } for (i=1;i<=n;i++) a[x][i]=0; visit[x]=0; printf("%d",x); if (step) printf(" "); else printf("\n"); sort(); return 0;}int main(){int x,y,i,j,m; while (scanf("%d%d",&n,&m),n+m) {for (i=1;i<=n;i++) for (j=1;j<=n;j++) a[i][j]=0; for (i=1;i<=n;i++) visit[i]=1; for (i=1;i<=m;i++) {scanf("%d%d",&x,&y); a[x][y]=1; } step=n; sort(); } return 0;}
- uva 10305 - Ordering Tasks
- uva 10305 - Ordering Tasks
- uva 10305 - Ordering Tasks
- UVa 10305 - Ordering Tasks
- uva-10305 - Ordering Tasks
- UVa 10305 - Ordering Tasks
- UVa 10305 - Ordering Tasks
- UVA 10305 Ordering Tasks
- UVa 10305Ordering Tasks
- Uva 10305 - Ordering Tasks
- uva 10305Ordering Tasks
- uva 10305 - Ordering Tasks
- uva 10305 Ordering Tasks
- UVa 10305 - Ordering Tasks
- UVA 10305 - Ordering Tasks
- Ordering Tasks UVA 10305
- UVA - 10305 Ordering Tasks
- UVA - 10305 Ordering Tasks
- ORACLE实现分布式数据库应用
- 带CheckBox列头的DataGridView(一)
- Java中如何使封装自己的类,建立并使用自己的类库?
- 跨平台移动开发实战(九)------移动端本地存储方案
- MFC中Tab Control的使用
- uva 10305 - Ordering Tasks
- 通过Java编程处理XML 为SOA减少内存占用
- CX51 用户手册----RET_PSTK伪指令
- 移位运算符
- zip解压
- struts2 通配符和属性技巧
- struts+hibernate+spring 版本控制svn的URL地址
- Android 4.1:UI开源,连接,服务和工具 全面升级
- error prj0019 running moc on ""