HDU 2647 Reward
来源:互联网 发布:超链接调用js方法 编辑:程序博客网 时间:2024/06/16 06:51
Reward
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10105 Accepted Submission(s): 3219
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 one may have demands of the distributing of rewards ,just like a's reward should more than b's.Dandelion's unclue wants to fulfill all the demands, of course ,he wants to use the least money.Every work's reward will be at least 888 , because it's a lucky number.
The workers will compare their rewards ,and some one may have demands of the distributing of rewards ,just like a's reward should more than b's.Dandelion's unclue wants to fulfill all the demands, of course ,he wants to use the least money.Every work's reward will be at least 888 , because it's a lucky number.
Input
One line with two integers n and m ,stands for the number of works and the number of demands .(n<=10000,m<=20000)
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
Output
For every case ,print the least money dandelion 's uncle needs to distribute .If it's impossible to fulfill all the works' demands ,print -1.
Sample Input
2 11 22 21 22 1
Sample Output
1777-1题意: 给你n个工人 老板要给工人发奖金,奖金最低为 888 给你m个关系 a b 表示a的奖金要比b的奖金多。。问你老板最少要花费多少钱 如果矛盾的话 ,就输出-1 。思路 : 存图的时候注意要是钱最小的为没有入度的点。 ans 记录每个人的得到的最少的钱。 fincnt 判断是否有矛盾存在如果有矛盾存在那么 fincnt不可能等于n 。代码:#include<stdio.h>#include<string.h>#include<queue>#include<iostream>#include<algorithm>#define N 105using namespace std;struct node{int u,v,next;}edge[N];int ingree[N],head[N];int n,m,cnt,fin;void add(int u,int v){edge[++cnt].u=u;edge[cnt].v=v;edge[cnt].next=head[u];head[u]=cnt;return ;}int main(){int u,v,i;while(scanf("%d %d",&n,&m)!=EOF){if(n==0&&m==0) break;memset(ingree,0,sizeof(ingree));cnt=0;memset(head,-1,sizeof(head));for(i=1;i<=m;i++){scanf("%d %d",&u,&v);add(u,v);ingree[v]++;}fin=0;queue< int >q;for(i=0;i<n;i++){if(ingree[i]==0){q.push(i);fin++;}}int temp;while(!q.empty()){temp=q.front();//printf("%d ",temp);q.pop();for(int k=head[temp];k!=-1;k=edge[k].next){v=edge[k].v;ingree[v]--;if(ingree[v]==0){fin++;q.push(v);}}}if(fin==n) printf("YES\n");else printf("NO\n");}return 0;}
阅读全文
0 0
- hdu 2647 Reward
- hdu 2647 Reward
- hdu 2647 Reward
- HDU 2647 Reward
- hdu 2647 Reward
- hdu 2647 Reward
- hdu-2647 Reward
- hdu 2647 Reward
- HDU 2647 Reward
- hdu 2647 Reward
- hdu 2647 Reward
- HDU 2647 Reward
- HDU 2647 Reward
- hdu 2647 Reward
- hdu 2647 Reward
- Hdu 2647 Reward
- hdu 2647 Reward
- HDU 2647 Reward
- 1701H2 王建瑜 2017.10.14 连续第四天总结
- 工具
- <深度学习系列>基于numpy和python的反向传播算法的实现与分析
- 考虑实现Comparable接口。
- 最近 5 年 133 个 Java 面试问题列表(下)
- HDU 2647 Reward
- 数字货币开发第一部分: 深度抽象算法Serenity教程
- Java Web项目中使用freemarker操作flt生成带图片(base64)的Word文档
- ubuntu 的ls 命令 的使用
- 二分图匹配 判断是否为二分图 —— 模板
- C++笔记——构造函数和析构函数
- OpenCV3_C++_Erode()图像的收缩 实例
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 【51Nod1500】苹果曼和树