HDU 2647】的更多相关文章

hdu 2647 Reward Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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…
HDU.2647 Reward(拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 这道题有一点变化是要求计算最后的金钱数.最少金钱值是888,最少的差额是1,如1号的人比2号钱要多,2号至少是1号人的钱数+1.根据拓扑排序的思想,我们只需要类比二叉树的层序遍历,每次取出入度为0的节点做处理,累加金钱数量,然后再取出入度为0的节点处理.直到取出所有的点或者判断成环即可. 代码总览 #include <iostream> #include <…
题目链接: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…
Reward HDU - 2647 题意:每个人的起始金额是888,有些人觉得自己做的比另一个人好所以应该多得一些钱,问最少需要花多少钱,如果不能满足所有员工的要求,输出 -1 样例1: 2 1 1 2 输出1777 1认为自己的报酬应该比2多,所以2为888,1为889是最小的情况 样例2: 5 4 1 2 2 5 2 4 4 3 输出4446 相当于给定一张图,n个节点,m条边,问你是否存在环,若存在,则输出-1,为什么?因为存在环的话无法满足所有人的需求例如1->2,1->1,1想比2大…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2647 Reward 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 reward…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意是给你n点m条有向边,叶子点(出度为0)上的值为888,父亲点为888+1,依次计算... 让你求最小的值,但是中间出现有向环就不行了,输出-1. 拓扑排序队列实现,因为叶子是最小的,所以把边反向就可以求了. //拓扑队列实现 //就是先把入度为0的先入队,然后每次出队的时候把相邻的点的入度减1,要是入度为0则再入队,不断循环直到队列为空 //时间复杂度为O(N + E) //这题就是把边…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2647 老板给员工发工资,每个人的基本工资都是888,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员工的奖金多,老板满足了所以员工的这种心思,而且老板下午发的总工资最少,问最少是多少?比如 a b 表示a的工资比b要高(高一块钱),当出现a b   b c   c a这种环的时候输出-1 拓扑排序http://www.cnblogs.com/tonghao/p/4721072.html 小指向大…
题目链接: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…
思路:拓扑排序 #include<stdio.h> #include<string.h> typedef struct { int to; int next; }EdgeNode; EdgeNode Edge[20005]; int head[10005],node[10005]; int cnt,indegree[10005],vis[10005]; void init() { cnt = 0; memset(vis,0,sizeof(vis)); memset(head,-1,…
Reward 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 rewards. The workers will compare their rewards ,a…
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…
题目链接:https://vjudge.net/contest/218427#problem/C 题目大意: 老板要给很多员工发奖金, 但是部分员工有个虚伪心态, 认为自己的奖金必须比某些人高才心理平衡: 但是老板很人道, 想满足所有人的要求, 并且很吝啬,想画的钱最少 输入若干个关系 a b a c c b 意味着a 的工资必须比b的工资高 同时a 的工资比c高: c的工资比b高 当出现环的时候输出-1 #include<iostream> #include<cstring> #…
题目 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…
Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12918    Accepted Submission(s): 4129 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he…
题意:每个人的工资至少888,然后有m个条件,前者比后者要多.求最少工资. 分析: 最开始的开邻接矩阵的肯定超时,如果dfs,会出现由于刚开始不是从入度为0的点出发,后期修改不了.比较麻烦. 正确方式是,用队列实现,不需要像普通队列一样,用vis数组标记,而是根据入度是否为0的标准加入队列. /* #include <bits/stdc++.h> using namespace std; const int maxn = 10000+5; int n,m; vector<int>…
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11836 Accepted Submission(s): 3804 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants…
传送门     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 hav…
令每一个员工都有一个自己的等级level[i] , 员工等级越高,那么工资越高,为了使发的钱尽可能少,所以每一级只增加一单位的钱 输入a b表示a等级高于b,那么我们反向添加边,令b—>a那么in[a]++,再进行拓扑排序,每次都让边的终点的level值大于起始点,那么要用max取较大值 #include <iostream> #include <cstdio> #include <cstring> #include <queue> using nam…
Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9800    Accepted Submission(s): 3131 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he w…
#include<stdio.h> #include<queue> #include<vector> #include<iostream> using namespace std; #define  N  11000 int n,m,sum; int indegree[N],value[N]; vector<int>now[N]; int Max(int a,int b) { return a>b?a:b; } int find() {  …
#include<stdio.h> #include<queue> #include<iostream> using namespace std; #define  N  11000 int n,m,sum; struct node { int indegree,num; int value,next[300]; }now[N]; int Max(int a,int b) { return a>b?a:b; } int find() {        queue&…
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 rewards. The workers will compare their rewards ,and some…
RewardTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13132    Accepted Submission(s): 4199 Problem DescriptionDandelion's uncle is a boss of a factory. As the spring festival is coming , he wan…
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 rewards. The workers will compare their rewards ,and some…
拓扑排序 Week_10    C 题意:输入n行数据a,b  ,表示a的钱数大于b的钱数,最低的人分的的钱数为888,问最少需要多少钱可以分给员工 思路:标准的拓扑排序,不过这题需要逆向拓扑 注意点:1.如何判断途中有换,或者说有的点没有选择到,用个int整型cnt,利用拓扑排序的特点,每个点只查找一次,所以当cnt==n的时候,输出sum. 2.多组输入不要忘了初始化数组之类的 #include <iostream> #include <cmath> #include <…
1.拓扑排序的概念 对一个有向无环图(Directed Acyclic Graph简称DAG)G进行拓扑排序,是将G中所有顶点排成一个线性序列,使得图中任意一对顶点u和v,若边(u,v)∈E(G),则u在线性序列中出现在v之前. 2.拓扑排序的实现步骤 1. 在有向图中选一个没有前驱的顶点并且输出 2. 从图中删除该顶点和所有以它为尾的弧(白话就是:删除所有和它有关的边) 3. 重复上述两步,直至所有顶点输出,或者当前图中不存在无前驱的顶点为止,后者代表我们的有向图是有环的,因此,也可以通过拓扑…
A - Choosing Capital for Treeland CodeForces - 219D 题意:有一颗单向边的树,要选取一个结点作为首都.要求是这个结点到其它结点,总共需要翻转的路径数量最少(因为是单向边,翻转了才能到达另一个结点). 做法:树形dp. 代码:待补. B - Maximal Intersection CodeForces - 1029C 题意:给出n个区间,然后你可以删除一个区间,问你剩下的区间的交集的最大长度是多少. 思路:首先我们得先知道n条线段公共的线段一定是…
http://acm.hdu.edu.cn/showproblem.php?pid=2647 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9821    Accepted Submission(s): 3136 Problem Description Dandelion's uncle is a boss of a factory.…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…