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 ...
随机推荐
- hihocoder 神奇字符串
思路: 暴力,模拟. 实现: #include <iostream> #include <algorithm> #include <cstdio> #include ...
- 升级 Cocoapods 到1.2.0指定版本,降低版本及卸载
=====================升级版本=================== CocoaPods 1.1.0+ is required to build SnapKit 3.0.0+. 在 ...
- iOS programming Delegation and Text Input
iOS programming Delegation and Text Input 1.1 Text Fields CGRect textFieldRect = CGRectMake(40, ...
- 田字格布局html div
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 2015年度精品 最新力作32位和64位xp,win7,win8,win10系统下载(电脑城专用版)
一.系统主要特点 1.安装维护方便快速 - 全自动无人值守安装,采用万能GHOST技术,安装系统过程只需3-5分钟,适 合新旧各种机型. - 集成常见硬件驱动,智能识别+预解压技术,绝大多数硬件可以快 ...
- 强大的云存储与应用管理工具DzzOffice1.0 Beta(大桌子办公)发布下载
之前在9月份我们发布了一份内测版,得到了1000多位朋友参与下载测试.经过2个月,结合测试后朋友们反馈的问题,和开发建议.终于完成了这次Beta版的开发.感谢这两个月中参与测试,和帮助我们完善程序的朋 ...
- Objective-C 是动态语言
Objective-C 的动态性是由 runtime 相关的库赋予的. 当然其他语言也完全可以运行在一个 Runtime 库上而获得动态性,由于多数高级语言的诞生都对应着一种编译器,因此将编译器的特性 ...
- git 提交运用vim编辑器
git commit -m 默认使用nano,觉得不爽,改成vim吧.在 .gitconfig (在根目录下)的 [core] 段中加上 editor=vim . 或:$git config -- ...
- 04C#运算符
C#运算符 运算符分类 与C语言一样,如果按照运算符所作用的操作数个数来分,C#语言的运算符可以分为以下几种类型: l 一元运算符:一元运算符作用于一个操作数,例如:-X.++X.X--等. l ...
- ubuntu apt-update NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
Fetched 28.1 MB in 11s (2344 kB/s) W: GPG error: http://archive.canonical.com xenial Release: The fo ...