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 ...
随机推荐
- pgm转jpg
clc;clear all;for i=1:40for j=1:10image=imread(strcat('N:\FACE\orl_faces\s',...int2str(i),'\',int2st ...
- IDEA的注册
步骤: license server -> 属性 -> 允许作为程序执行文件 即 chmod 777
- Java学习之路(转)
我也搞了几年JAVA了.因为一向懒惰,没有成为大牛,仅仅是一普通程序员,不爱玩社交站点.不爱玩微博,只有喜欢百度贴吧,潜水非常久了,手痒来给新人分享下从新手成长为老鸟的已见,也刷刷存在感,应该不比曝照 ...
- GUI程序设计3
16. 树(JTree)使用示例 例16.1 创建JTree示例. package GUI1; import java.awt.BorderLayout; import java.awt.Contai ...
- 我所遭遇过的游戏中间件--Havok
我所遭遇过的游戏中间件--Havok Havok是我接触的第一款游戏中间件,那是在五,六年前,我刚刚毕业,对游戏开发还是个菜鸟.我记得先是对游戏场景中的地形和其他静态物体生成刚体,然后做角色的Ragd ...
- Java 动态向 JTable 中添加数据
import java.awt.Toolkit; import javax.swing.SwingUtilities; import javax.swing.UIManager; import jav ...
- C# 特性(Attribute)(二)
AttributeUsage类是另外一个预定义特性类,它帮助我们控制我们自己的定制特性的使用.它描述了一个定制特性如和被使用. AttributeUsage有三个属性,我们可以把它放置在定制属性 ...
- Android直播实现 Android端推流、播放
最近想实现一个Android直播,但是对于这方面的资料都比较零碎,一开始是打算用ffmpeg来实现编码推流,在搜集资料期间,找到了几个强大的开源库,直接避免了jni的代码,集成后只用少量的java代码 ...
- 计算两端yuv视频流中每一帧的ssim值
方法同上一篇,仅仅不多这里在计算的时候用了opencv1的接口,出现了一些问题.最后总算攻克了. 程序: #include <stdlib.h> #include <stdio.h& ...
- MySQL数据源在Spring中的配置
干脆把MySQL的数据源配置也一起放这里,以备不时之需. MySQL的驱动包可以从这里 http://pan.baidu.com/s/1d02aZ 下载. 以下粗体部分是需要你根据实际情况调整的. & ...