拓扑排序结合代码的完整理解

确定比赛名次

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9284    Accepted Submission(s): 3613
Problem Description
有N个比赛队(1<=N<=500),编号依次为1,2,3,。。。。,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道每场比赛的结果,即P1赢P2,用P1,P2表示,排名时P1在P2之前。现在请你编程序确定排名。
 
Input
输入有若干组,每组中的第一行为二个数N(1<=N<=500),M;其中N表示队伍的个数,M表示接着有M行的输入数据。接下来的M行数据中,每行也有两个整数P1,P2表示即P1队赢了P2队。
 
Output
给出一个符合要求的排名。输出时队伍号之间有空格,最后一名后面没有空格。

其他说明:符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前;输入数据保证是正确的,即输入数据确保一定能有一个符合要求的排名。

 
Sample Input
4 31 22 34 3
 
Sample Output
1 2 4 3
 
Author
SmallBeer(CML)
赤裸裸的拓扑排序.....
代码:

 
/*@coder Gxjun*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 505
bool map[maxn][maxn];
int indegree[maxn],tp[maxn],n,m;
void tuopu_sort()
{
    ,sizeof(tp)); //拓扑排序数组清空
    ,ll;
    ;i<=n;i++)
    {
;j<=n;j++)
        {
         /*每次取出入读位0的数*/
)
            {
                indegree[j]=-1;  //让他等于-1;表示舍弃掉这个数
                tp[k++]=j;  //放到拓扑序列中 
                /*进行一次循环,去掉所有这个数指向的数的一个度*/
;ll<=n;ll++)
                {
                    if(map[j][ll])  //j-->LL 表示成为map[j][ll]
                    {
                        indegree[ll]--;  //减少一个
                    }
                }
                break;  // 终止,然后进行下次的查找
            }
        }
        if(j>n)
        {
            //这表示构成了一个环
            return ;  //之间结束即可,但是在其他的题中,不能这样...
        }
    }
 
}
 
int main()
{
    ,fx,ty;//  fx--->from x to y
    while(scanf("%d%d",&n,&m)!=EOF)
    {
,sizeof(map));  
,sizeof(indegree));
;i<m;i++)
        {
            scanf("%d%d",&fx,&ty);
            if(!map[fx][ty])      //防止数据重复
            {
              map[fx][ty]=true;  
              indegree[ty]++;     //入度加一
            }
        }
        tuopu_sort();
;i<n-1;i++)
        {
            printf("%d ",tp[i]);
        }
        printf("%d\n",tp[i]);
    }
 
    ;
}
 
 可以结合这个ppt,相信自己保证会....
http://wenku.baidu.com/view/35629a8ad0d233d4b14e69fd.html 

hduoj------确定比赛名次的更多相关文章

  1. hduoj 1285 确定比赛名次

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...

  2. HDU 1285 确定比赛名次(简单拓扑排序)

    题目链接: 传送门 确定比赛名次 Time Limit: 1000MS     Memory Limit: 65536K Description 有N个比赛队(1 Input 输入有若干组,每组中的第 ...

  3. ACM: HDU 1285 确定比赛名次 - 拓扑排序

     HDU 1285 确定比赛名次 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  4. HDU 1285 确定比赛名次

    传送门 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. HDU 1285 拓普排序 基本模板例题 确定比赛名次

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. TOJ3651确定比赛名次

    确定比赛名次   Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte Total Submit: 23          ...

  7. (hdu)1285 确定比赛名次

    Problem Description 有N个比赛队(<=N<=),编号依次为1,,,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接 ...

  8. hdoj 1285 确定比赛名次【拓扑排序】

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. 确定比赛名次(map+邻接表 邻接表 拓扑结构 队列+邻接表)

    确定比赛名次 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  10. B - 确定比赛名次

    B - 确定比赛名次 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

随机推荐

  1. CentOS6.5升级autoconf版本 Autoconf version 2.64 or higher is required

    安装软件时提示说需要Autoconf 2.64或更高的版本 [root@BobServerStation twemproxy]# autoconf configure.ac:8: error: Aut ...

  2. SSM(SpringMVC+Spring+Mybatis)框架程序on IDEA

    有了之前文章搭建的SSH框架之后,现在搭建基于Mybatis的框架.主要基于如下这篇文章: http://blog.csdn.net/gallenzhang/article/details/51932 ...

  3. Surrounded Regions leetcode java

    题目: Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is capt ...

  4. 五条强化 SSH 安全的建议

    当你查看你的 SSH 服务日志,可能你会发现充斥着一些不怀好意的尝试性登录.这里有 5 条常规建议(和一些个别特殊策略)可以让你的 OpenSSH 会话更加安全. 强化密码登录 密码登录很方便,因为你 ...

  5. 如何在Ubuntu 16.04中创建GIF动图

    导读 FFmpeg 是一款开源的音.视转换器,使用 FFmpeg 我们可以非常容易地转换和录制音视频文件,而 ImageMagick 是一款用于创建.编辑和合并位图图像的一款开源软件. 大家经常在新浪 ...

  6. 为什么空格拷贝到linux 会变成两个

    为什么空格拷贝到linux 会变成两个 学习了:https://zhidao.baidu.com/question/266438357.html 在vi界面内输入:set paste 然后进行拷贝: ...

  7. 动态改变UIPopupList选项(NGUI)

    NGUI的UIPopupList 可以通过修改items属性来动态改变菜单选项: public class popListvahnge : MonoBehaviour { public UIPopup ...

  8. PCL学习笔记二:Registration (ICP算法)

    原文:http://blog.csdn.net/u010696366/article/details/8941938 PCL Registration API Registration:不断调整,把不 ...

  9. Font Awesome使用简介

      Font awesome是一种用字体来实现图标的CSS插件. 使用方法: 到http://fortawesome.github.io/Font-Awesome/ 下载代码包. 代码包解压到本地后, ...

  10. 【leetcode 桶排序】Maximum Gap

    1.题目 Given an unsorted array, find the maximum difference between the successive elements in its sor ...