首页 > 其他 > 详细

HDU 1285 确定比赛名次

时间:2014-02-24 03:24:05      阅读:339      评论:0      收藏:0      [点我收藏+]

题解:裸的topo,注意判重,由于数据升序所以免排序。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cstdio>
#include <iostream>
using namespace std;
#define N 505
int map[N][N],n,m,a,b,in[N],ans[N];
void topo(){
    int top=0,i;
    memset(ans,0,sizeof ans);
    while(true){
        for(i=1;i<=n;i++)if(in[i]==0)break;
        if(i==n+1)return;
        in[i]=-1;
        ans[top++]=i;
        for(int x=1;x<=n;x++)if(map[i][x])in[x]--;
    }
}
int main(){
    while(~scanf("%d%d",&n,&m)){
        memset(map,0,sizeof map);
        memset(in,0,sizeof in);
        for(int i=0;i<m;i++){
            scanf("%d%d",&a,&b);
            if(!map[a][b]){
                map[a][b]++;
                in[b]++;
            }
        }
        topo();
        printf("%d",ans[0]);
        for(int i=1;i<n;i++)printf(" %d",ans[i]);
        printf("\n");
    }
}

HDU 1285 确定比赛名次

原文:http://www.cnblogs.com/forever97/p/3561923.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!