Poj(2367),拓扑排序
题目链接:http://poj.org/problem?id=2367
题意: 知道一个数n, 然后n行,编号1到n, 每行输入几个数,该行的编号排在这几个数前面,输出一种符合要求的编号名次排序。
拓扑排序:
先找入度为0的点,再根据这个点删掉与之相连的点之间的弧,入度减一。
#include <stdio.h> int maps[][];
int degree[]; int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int to;
while(scanf("%d",&to),to)
{
maps[i][to] = ;
degree[to] ++;
}
} int ans[];
int pos=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(degree[j]==)
{
ans[pos++] = j;
degree[j] = -;
for(int k=;k<=n;k++)
{
if(maps[j][k]==)
degree[k] --;
}
break;
}
}
} for(int i=;i<n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-]); return ;
}
Poj(2367),拓扑排序的更多相关文章
- poj 2367 拓扑排序入门
Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when ...
- poj 3687(拓扑排序)
http://poj.org/problem?id=3687 题意:有一些球他们都有各自的重量,而且每个球的重量都不相同,现在,要给这些球贴标签.如果这些球没有限定条件说是哪个比哪个轻的话,那么默认的 ...
- POJ 3249 拓扑排序+DP
貌似是道水题.TLE了几次.把所有的输入输出改成scanf 和 printf ,有吧队列改成了数组模拟.然后就AC 了.2333333.... Description: MR.DOG 在找工作的过程中 ...
- poj 3249 拓扑排序 and 动态规划
思路:我们首先来一遍拓扑排序,将点按先后顺序排列于一维数组中,然后扫描一遍数组,将每个点的出边所连接的点进行更新,即可得到最优解. #include<iostream> #include& ...
- poj 2585 拓扑排序
这题主要在于建图.对9个2*2的小块,第i块如果出现了不等于i的数字,那么一定是在i之后被brought的.可以从i到该数字建一条边. 图建好后,进行一次拓扑排序,判段是否存在环.若存在环,那么就是B ...
- Sorting It All Out POJ - 1094 拓扑排序
题意:给N个字母,和M个偏序关系 求一个可确定的全序,可确定是指没有其他的可能例如A>B D>B 那么有ADB DAB两种,这就是不可确定的其中,M个偏序关系可以看做是一个一个按时间给出的 ...
- nyoj 349 (poj 1094) (拓扑排序)
Sorting It All Out 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 An ascending sorted sequence of distinct ...
- Poj(3687),拓扑排序,
题目链接:http://poj.org/problem?id=3687 题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小.(先保证1号 ...
- POJ 1094 拓扑排序
Description: 规定对于一个只有大写字母的字符串是有大小顺序的.如ABCD.即A<B.B<C.C<D.那么问题来了.现在第一行给你n, m代表序列里只会出现前n的 ...
- POJ 1128 拓扑排序 + 深搜
/* (⊙v⊙)嗯 貌似是一个建图 拓扑+深搜的过程.至于为什么要深搜嘛..一个月前敲得题现在全部推了重敲,于是明白了.因为题意要求如果有多个可能的解的话. * 就要输出字典序最小的那个.所以可以对2 ...
随机推荐
- linux 缺少动态连接库.so--cannot open shared object file: No such file or directory
error while loading shared libraries的解決方法 执行行程式時,如此遇到像下列這種錯誤: ./tests: error while loading shared l ...
- 当As3遇见Swift(三)
类 As3 Swift中似乎没有包,包路径的概念.因而显得简洁的多. package { public class ShuaiGe { } } Swift类 class ShuaiGe{ } 类的构造 ...
- PostgreSQL pg_dump pg_dumpall and restore
pg_dump dumps a database as a text file or to other formats. Usage: pg_dump [OPTION]... [DBNAME] Gen ...
- G面经prepare: Data Stream Average
给一个datastream和一个fixed window size, 让我design一个class可以完成add number还有find average in the window. 就是不能用v ...
- Lintcode: Rehashing
The size of the hash table is not determinate at the very beginning. If the total size of keys is to ...
- cpp quiz
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream&g ...
- Java SE series:1. environment configure and Hello world! [We use compiler and packager to create an application!]
1. cli (command line interface) and gui (graphic user interface) use javahome path, search classpath ...
- ServiceController1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- csuoj 1115: 最短的名字
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1115 1115: 最短的名字 Time Limit: 5 Sec Memory Limit: 6 ...
- jvm笔记
-vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M 1. 各个参数的含义什么? 参数中-vmargs的意思是设置JVM参数, ...