hdoj 2647 Reward【反向拓扑排序】】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewar…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工资为888,求最少要发多少工资,如果关系矛盾就输出“-1”. 解题思路:用拓扑排序解决,但是要分层,类似于多棵树的层次遍历,用dis[i]存储i所在层数(起点为0层),因为要是所有条件都符合,所以dis[i]取最大值.还有注意判断是否存在环. 代码: #include<iostream> #inc…
题目 Reward Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards.  The workers will compare their rewards ,and some one may…
Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13509    Accepted Submission(s): 4314 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he w…
Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards. The workers will compare their rewards ,and some one may…
Reward Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 51   Accepted Submission(s) : 21 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Dandelion's uncle is a boss of…
http://codeforces.com/contest/825/problem/E 一道裸的拓扑排序题.为什么需要反向拓扑排序呢?因为一条大下标指向小下标的边可能会导致小下标更晚分配到号码,导致字典序增大.而反向拓扑排序在上述情况,只会使大序号更晚分配到序号,而小序号还是较小的,根据字典序比对规则,当然是选择反向拓扑排序啦. #include <iostream> #include <queue> #include <cstdio> #include <vec…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 题面是中文题面,就不解释题意了,自己点击链接去看下啦~这题排序有两个条件,一个是按给定的那个序列(即输入的u,v,优先级最高),一个是序号从小到大(优先级次之).正向的话由于这两个条件不好维护,所以就想着用反向拓扑排序来实现.首先记录每个节点的出度,然后用优先队列来维护顺序(使用默认的从大到小排序),最后反向输出即可. 代码实现如下: #include <queue> #include &l…
HDU-4857 题意就是做一个符合条件的排序,用到拓扑序列. 我一开始wa了多发,才发现有几个样例过不了,发现1->2->3...的顺序无法保证. 后来就想用并查集强连,还是wa: 后来发现发用反向拓扑排序+优先队列才可以通过: 这里注意把入度为0的入队改成了出度为0的入队 下面是AC代码: #include <cstring> #include<queue> #include <cstdio> using namespace std; vector<…
Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5617    Accepted Submission(s): 1707 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wa…