Ordering Tasks---点任务(拓扑)

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1246


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 be m lines with two integers i and j, representing the fact that task i must be executed before task j. 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

题意:

 每一项任务都有一个编号,输入的两个编号表示只有做过前边的编号任务才能接着去做后边的编号任务,

让我们输出做任务的顺序.

附上ac代码:

ps:我的第一个拓扑题,嘿嘿嘿~

#include<stdio.h>
#include<string.h>
int a[110],b[110],t[110],book[110],s[110];
int main()
{
    int n,m;
    while(~scanf("%d %d",&n,&m)&&(n+m))
    {
        memset(t,0,sizeof(t));
        memset(s,0,sizeof(s));
        memset(book,0,sizeof(book));
        for(int i=0; i<m; i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            s[b[i]]++;              ///入度加一
        }
        int k=0;
        for(int i=1; i<=n; i++)
        {
            if(s[i]==0)
            {
                book[i]=1;            ///标记
                t[k++]=i;                 ///入度为零的存进t数组
            }
        }
        for(int i=0; i<n; i++)              ///t数组中一个一个判断
        {
            for(int j=0; j<m; j++)          ///m个关系   依次判断
            {
                if(t[i]==a[j])         ///与a[i]有关系的b[i]入度--
                {
                    s[b[j]]--;
                    if(s[b[j]]==0)
                    {
                        t[k++]=b[j];         ///入度为零  存入t数组
                    }
                }
            }
        }
        for(int i=0; i<n; i++)
            if(i<n-1)printf("%d ",t[i]);       ///格式
            else printf("%d\n",t[i]);
    }
    return 0;
}

 

 每个人都有一个觉醒期,但觉醒的早晚决定个人的命运。

觉醒期的到来有四个条件:

一是好学,觉得自己永远不够完美,就是俗话说的“活到老学到老”;

二是发现,对他人有优于自己的接人待物和处事方式特别敏感,时刻记得“三人之行必有我师”;

三是把他人优于自己的东西融合到自己的思想上。坚持以上三点,慢慢的你的认识就会逐步完善和提高,完善和提高的过程就是所谓的觉醒期;

最后一个条件就是,当生活给人重重一击的时候,如果这个人没有被击倒,还在努力向上的生活,就是觉醒最快的时候。

 下面是一个友人(烟台大学)的校训:

 守信 求实 好学 力行

重诚信是中华文化的精髓,也是为人立身之本;求真务实是中国共产党党的光荣传统,也是事业成功的保证。该校训强调崇尚诚信,注重实效,追求真理,开拓创新,以好学的精神求智,以力行的精神履践仁道。子曰:“好学近乎智,力行近乎仁,知耻近乎勇。”将此作为修身的根本,持志力行,勤勉进取,以求达到智者不惑、仁者不忧、勇者不惧、诚信求实畅行天下的理想人生境界。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵩韵儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值