HDU——2647 Reward
Reward
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9800 Accepted Submission(s): 3131
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.
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
1 2
2 2
1 2
2 1
-1
问题描述
蒲公英的叔叔是工厂的老板。 随着春节来临,他想向他的工人分发奖励。 现在他有分享奖励的麻烦。
工作人员会比较他们的回报,有的可能会有分配奖励的要求,就像一个奖励应该超过b's.蒲公英的无礼想要完成所有的要求,当然,他想使用最少的钱。每个工作 奖励至少是888,因为这是一个幸运数字。
#include<queue> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 20100 #define money 888 using namespace std; queue<int>q; long long anss; int n,m,x,y,s,in[N],tot,sum,head[N],ans[N]; int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch=getchar();} return x*f; } struct Edge { int from,to,next; }edge[N]; int add(int x,int y) { tot++; edge[tot].to=y; edge[tot].next=head[x]; head[x]=tot; } void begin() { s=,sum=,tot=;anss=; memset(,sizeof(in)); memset(ans,,sizeof(ans)); memset(head,,sizeof(head)); memset(edge,,sizeof(edge)); } int main() { while(scanf("%d%d",&n,&m)!=EOF) { begin(); ;i<=m;i++) { x=read(),y=read(); add(y,x),in[x]++; } ;i<=n;i++) ) q.push(i),ans[i]=0; while(!q.empty()) { x=q.front(),q.pop(),sum++; for(int i=head[x];i;i=edge[i].next) { int t=edge[i].to; in[t]--; ) q.push(t),ans[t]=ans[x]+1; } } if(sum!=n) printf("-1\n"); else { ;i<=n;i++) anss+=money+ans[i]; printf("%lld\n",anss); } } ; }
HDU——2647 Reward的更多相关文章
- ACM: hdu 2647 Reward -拓扑排序
hdu 2647 Reward Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Des ...
- HDU.2647 Reward(拓扑排序 TopSort)
HDU.2647 Reward(拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 这道题有一点变化是要求计算最后的金钱数.最少金钱值是888,最少的 ...
- 题解报告:hdu 2647 Reward(拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...
- hdu 2647 Reward
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2647 Reward Description Dandelion's uncle is a boss o ...
- HDU 2647 Reward (拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意是给你n点m条有向边,叶子点(出度为0)上的值为888,父亲点为888+1,依次计算... ...
- HDU 2647 Reward(拓扑排序+判断环+分层)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工 ...
- HDU 2647 Reward(图论-拓扑排序)
Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is comin ...
- hdu 2647 Reward(拓扑排序,反着来)
Reward Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- HDU 2647 Reward 【拓扑排序反向建图+队列】
题目 Reward Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to d ...
- HDU 2647 Reward(拓扑排序,vector实现邻接表)
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
随机推荐
- mysql之通过cmd连接远程数据库
---恢复内容开始--- 目录 前提 连接远程数据库 前提: 本地安装了mysql数据库 本地和远程网络是连通的,通过命令ping ip (即ping 192.168.0.333),可以ping通 连 ...
- apache设置无缓存
打开httpd.conf 开启扩展 确保开启 LoadModule headers_module modules/mod_headers.so 添加配置项 并添加以下配置,跟据文件类型来让浏览器每次都 ...
- Can't find bundle for base name messages.AndroidJpsBundle, locale zh_CN
从http://www.android-studio.org/网站上下载了一个Android Studio 3.0的非安装版本(android-studio-ide-171.4408382-wind ...
- Struts1 MVC框架的工作原理
MVC英文及Model-View-Controller,分别是模型(Model),视图(View)和控制(Controller).MVC模式的目的是实现web系统的职能分工. View:即用户交互界面 ...
- JavaScript——XMLHttpRequest 家族
https://www.zhangxinxu.com/wordpress/2013/10/understand-domstring-document-formdata-blob-file-arrayb ...
- 异步编程when.js
when.js很小,压缩后只有数kb,gzip后的大小几乎可以忽略.在Node和浏览器环境里都可以使用when.js 首先,我们看一小段代码: var getData = function(callb ...
- C#解析单层html的中的文本,然后拼接起来
匹配单层html的小demo,应该能匹配大多数html字符串.多层(嵌套)html标签解析不出来.可能有小bug,我抛砖引玉下,哈哈. using System; using System.Colle ...
- SQL Server错误: 0 解决方案
1.已设置两种登录模式. 2.SQL Server配置管理器已配置好. 按Windows徽标键+R组合键,然后输入cmd. 再然后输入netsh winsock reset.接下来重启电脑,应该就可以 ...
- Linux运维到底是做什么的?在开始学习之前,你必须了解这些!
首先祝贺你选择学习Linux,你可能即将踏上Linux的工作之旅,出发之前,让我带你来看一看关于Linux和Linux运维的一切. Linux因其高效率.易于裁剪.应用广等优势,成为了当今中高端服务器 ...
- 3D超炫酷旋转
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...