题意:n个任务,m组数据,每组数据输入x,y代表如果想要完成y任务需要先完成x任务,最后输出任务的完成顺序。
经典的拓扑排序。
代码:
#include
#include
#include
#include
#include
#include
using namespace std;
int map[105][105];
int num[105];
int n...
分类:
编程语言 时间:
2015-01-22 18:05:53
阅读次数:
130
Randomized quicksort(随机化快速排序)running time is independent of input ordering.no assumption about the input distribution.(无需对输入序列分布做任何假设)no specific inpu...
分类:
编程语言 时间:
2015-01-04 22:48:05
阅读次数:
443
类实现了Comparable接口就表明类的实例本身具有内在的排序关系(natural ordering)。因此,该类可以与很多泛型算法和集合实现进行协作。而我们之需要实现Comparable接口唯一的方法——compareTo。 以下是相关规则:sgn(x.compareTo(y)) = -sgn....
分类:
其他好文 时间:
2014-12-30 21:53:27
阅读次数:
231
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 5 namespace Linq101 6 { 7 class Ordering 8 { 9 /...
分类:
其他好文 时间:
2014-12-30 18:33:51
阅读次数:
138
Description
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 wi...
分类:
其他好文 时间:
2014-12-17 21:00:12
阅读次数:
202
该模块为高阶函数提供支持——作用于或返回函数的函数被称为高阶函数。在该模块看来,一切可调用的对象均可视为本模块中所说的“函数”。 目录 一、模块方法 1. functools.cmp_to_key(func) 2.functools.total_ordering(cls) ...
分类:
编程语言 时间:
2014-12-17 12:37:23
阅读次数:
140
UVA - 10305
Ordering Tasks
Time Limit: 3000MS
Memory Limit: Unknown
64bit IO Format: %lld & %llu
Submit Status
Description
Problem F
Ordering Tasks
Input: standard inp...
分类:
编程语言 时间:
2014-12-16 22:39:59
阅读次数:
264
题目大意:有n个变量,和m个二元组关系。关系(x,y)表示x<y。现在讲所有变量
从小到大来排序,进行输出。
例如:有4个变量a、b、c、d,若a<b,c<b,d<c,则排序后的可能为a<d<c<b,
也有其他可能d<a<c<d。只要输入其中一个就可。
思路:把n个变量看成是n个点,“x<y”看做是一条边,则得到一个有向图。对图的
节点进行排序,使得每一条有向边(x,y)对应的x都在y前边。即所谓的拓扑排序。
DFS进行拓扑排序,如果存在有向环,则不存在拓扑排序,否则就将访问完的结点
假如到当前拓扑序列的前...
分类:
编程语言 时间:
2014-12-12 20:53:23
阅读次数:
207
如果编写的判断式不满足strict weak ordering,就会出现Invalid operator< assertion error错误。网页:http://support.microsoft.com/kb/949171VS(其他编译器还没试过)中,sort函数要求比较函数是strict we...
分类:
其他好文 时间:
2014-12-06 20:13:54
阅读次数:
182
10305 - Ordering Tasks
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 i...
分类:
编程语言 时间:
2014-12-04 01:01:21
阅读次数:
280