http://poj.org/problem?id=2367

题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0。

这是一个特别裸的拓扑排序的一个题目,拓扑排序我也是刚刚才接触,想法还是挺简单的。实现起来也不复杂。

 #include <stdio.h>
#include <string.h> int Indegree[],n; bool mp[][]; int topsort()
{
for(int i=;i<=n;i++)
for(int j=;j<=n;j++) //遍历n次,找到第一个度为0的点,度为0的点,即排在这个点前面的点要么是没有,要么是已经输出了。
{
if(Indegree[j]==)
{
Indegree[j]--;
printf("%d",j);
if(i!=n) printf(" ");
else printf("\n");
for(int k=;k<=n;k++) //排在这个度为0后面的点,度都可以相应的减一,因为在它们的前面的点已经少了一个。
{
if(mp[j][k]) Indegree[k]--;
}
break;
} }
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int x;
scanf("%d",&n);
memset(mp,false,sizeof(mp));
for(int i=;i<=n;i++)
{
while(scanf("%d",&x),x)
{
mp[i][x]=true;
Indegree[x]++;
}
} topsort();
return ;
}

POJ 2367 (裸拓扑排序)的更多相关文章

  1. Poj(2367),拓扑排序

    题目链接:http://poj.org/problem?id=2367 题意: 知道一个数n, 然后n行,编号1到n, 每行输入几个数,该行的编号排在这几个数前面,输出一种符合要求的编号名次排序. 拓 ...

  2. HDU 3342 -- Legal or Not【裸拓扑排序 &amp;&amp;水题 &amp;&amp; 邻接表实现】

    Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  3. poj 1270(dfs+拓扑排序)

    题目链接:http://poj.org/problem?id=1270 思路:就是一简单的dfs+拓扑排序,然后就是按字典序输出所有的情况. http://paste.ubuntu.com/59872 ...

  4. poj 3683(2-sat+拓扑排序)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11127   Accep ...

  5. poj 1094(拓扑排序)

    http://poj.org/problem?id=1094 题意:给你m个字母,有n个判断语句.求在哪个语句就可以判断出这个是不是一个环,或者在哪个语句可以判断出这些字母的排序规则,或者就是不能确定 ...

  6. 【POJ 1094】拓扑排序

    题意 给出n,代表有以A开始的n个字母,给出它们的m个小于关系(A<B).如果前i个关系可以确定n个字母的一个顺序就输出: Sorted sequence determined after i ...

  7. POJ2367 Genealogical tree (拓扑排序)

    裸拓扑排序. 拓扑排序 用一个队列实现,先把入度为0的点放入队列.然后考虑不断在图中删除队列中的点,每次删除一个点会产生一些新的入度为0的点.把这些点插入队列. 注意:有向无环图 g[] : g[i] ...

  8. 杭电ACM1285----确定比赛名次『拓扑排序』

    //裸拓扑排序,注意先输出比较小的数,使用优先队列即可 #include <cstdio> #include <vector> #include <cstring> ...

  9. 图论之拓扑排序 poj 2367 Genealogical tree

    题目链接 http://poj.org/problem?id=2367 题意就是给定一系列关系,按这些关系拓扑排序. #include<cstdio> #include<cstrin ...

随机推荐

  1. jar tvf study.war jar命令查看war/jar包的内容

    jar tvf study.war 0 Thu Oct 20 14:01:18 CST 2016 META-INF/ 137 Thu Oct 20 14:01:16 CST 2016 META-INF ...

  2. phpmyadmin 链接远程mysql

    这个只是自己的笔记 新手 不记下来以后又忘记了~ 在这以前已经给mysql设置了可以远程连接的账户 版本 phpMyAdmin-4.2.11-all-languages 解压到D盘下www   本地环 ...

  3. [webgrid] – header - (How to Add custom html to Header in WebGrid)

    How to Add custom html to Header in WebGrid MyEvernote Link Posted on March 30, 2013by mtryambake Ho ...

  4. knockout-validation不自动插入错误消息

    <div data-bind="validationOptions:{insertMessages:false}"> <div class="valid ...

  5. python 跨语言数据交互、json、pickle(序列化)、urllib、requests(爬虫模块)、XML。

    Python中用于序列化的两个模块 json     用于[字符串]和 [python基本数据类型] 间进行转换 pickle   用于[python特有的类型] 和 [python基本数据类型]间进 ...

  6. 遍历JObject

    JObject jo = JObject.Parse(jsonStr); IEnumerable<JProperty> properties = jo.Properties(); fore ...

  7. XPath使用小结

    参考资料: http://www.w3school.com.cn/xpath/xpath_nodes.asp

  8. CF456B Fedya and Maths 找规律

    http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...

  9. http request method and response codes

    ============================ HTTP_Method============================ HTTP Method Action Examples GET ...

  10. bootstrap模版

    http://demo.cssmoban.com/cssthemes3/cpts_274_nz/forms.html