HDUOJ----2647Reward
Reward
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3129 Accepted Submission(s): 944
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.
- /*@coder 龚细军*/
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<queue>
- #include<vector> //动态的二维数组
- #include<iostream>
- using namespace std;
- const int maxn=;
- int n,m;
- int cnt[maxn],outd[maxn];
- vector< vector<int> >map(maxn);
- void tp_sort(int tol)
- {
- int i;
- queue<int>st;
- for(i=;i<=n;i++)
- {
- if(!outd[i])
- {
- outd[i]--;
- st.push(i);
- break;
- }
- }
- //环如何消除
- while(!st.empty())
- {
- int temp=st.front();
- vector<int>::iterator it;
- for(it=map[temp].begin();it!=map[temp].end();it++)
- {
- outd[*it]--;
- if(cnt[*it]<=cnt[temp])
- cnt[*it]=cnt[temp]+;
- }
- st.pop();
- for(i=;i<=n;i++)
- {
- if(!outd[i])
- {
- outd[i]--;
- st.push(i);
- break;
- }
- }
- }
- for(i=;i<=n;i++)
- {
- if(outd[i]!=-)
- {
- puts("-1");
- return ;
- }
- }
- int ans=;
- for(i=;i<=n;i++)
- {
- ans+=cnt[i];
- }
- if(ans)
- printf("%d\n",n*+ans);
- else
- puts("-1");
- }
- int main()
- {
- int a,b,i;
- while(scanf("%d%d",&n,&m)!=EOF)
- {
- for(i=;i<=n;i++) map[i].clear();
- memset(outd,,sizeof(outd));
- memset(cnt,,sizeof(cnt));
- i=;
- while(m--)
- {
- scanf("%d%d",&a,&b);
- map[b].push_back(a);
- outd[a]++; /*out++*/
- }
- tp_sort(i);
- }
- return ;
- }
HDUOJ----2647Reward的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hdu-oj 1874 畅通工程续
最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...
- HDUOJ题目HTML的爬取
HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 1286 找新朋友
http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hduoj 1285 确定比赛名次
http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...
随机推荐
- 微软企业库Unity学习笔记
本文主要介绍: 关于Unity container配置,注册映射关系.类型,单实例.已存在对象和指出一些container的基本配置,这只是我关于Unity的学习心得和笔记,希望能够大家多交流相互学习 ...
- 在mac上命令行里面如何打开文本编辑器?
在mac上命令行里面如何打开文本编辑器? 在linux命令行terminal上使用gedit直接就可以打开文本文件 那么在mac上面如何操作呢? 使用:open -a TextEdit setti ...
- 【BZOJ】【2752】【HAOI2012】高速公路(Road)
数学期望/线段树 然而又是一道road= =上一道是2750…… 下次不要一看期望题就弃疗么…… 期望题≠不可做题……!! 其实在这题中,期望就是(所有情况下 权值之和)/(总方案数) 因为是等概率抽 ...
- 新买的mac笔记本,发现vi编辑器没有颜色的解决方案
新买的mac笔记本,发现vi编辑器没有颜色的解决方案 我在网络上找了一些资料,发现都有些问题,尤其是一些让修改根目录上的文件,发现根本无法修改. 但是在网络上找到了这篇文章: http://super ...
- C#中三种定时器对象的比较 【转】
https://www.cnblogs.com/zxtceq/p/5667281.html C#中三种定时器对象的比较 ·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.W ...
- Windows下安装和配置Apache2.2.22服务器+PHP5+Mysql5
接下来,笔者将WindowsXP(Sp3)下,搭建和配置php运行环境做一个简单的介绍: 1.安装准备 1.1Apache下载,官方地址(http://httpd.apache.org/),此处笔者下 ...
- IOS开发之新浪微博OAuth2
说明:微博开放接口的调用,如发微博.关注等,都是需要获取用户身份认证的.目前微博开放平台用户身份鉴权主要采用的是OAuth2.0.为了方便开发者开发.测试自己的应用. OAuth2.0较1.0相比,整 ...
- 【转】NativeScript的工作原理:用JavaScript调用原生API实现跨平台
原文:https://blog.csdn.net/qq_21298703/article/details/44982547 -------------------------------------- ...
- 【Javascript Demo】无刷新预览所选择的图片
1.效果如下,可测试 2.代码如下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- WPF 下载网络文件 带进度条
附件:http://files.cnblogs.com/xe2011/WpfApplication3_downloadFile.rar 使用 private void Button ...