HDU 2647 Reward(拓扑排序)
来源:互联网 发布:伤害跳跃网络吧 编辑:程序博客网 时间:2024/04/27 09:07
题意:春节来临给员工发工资,有n名员工,m个要求,每个要求是 a b,意思a的工资要比b多。每个员工最低工资是888.问总共发放工资的最低是多少?
思路:从最低工资拓扑排序.排序的方向就是从低到高,(开始方向建错,W好几发)。最低888,依次+1,没有要求就是统一等级。
#include<bits/stdc++.h>using namespace std;int v[10010],ans[10010],vis[10010];vector<int>M[10010];int main(){ int n,m; while(~scanf("%d%d",&n,&m)){ for(int i=1;i<=n;i++) M[i].clear(); memset(v,0,sizeof(v)); memset(vis,0,sizeof(vis)); for(int i=0;i<m;i++){ int flag=0; int a,b;scanf("%d%d",&a,&b); M[b].push_back(a); v[a]++; } int t=0,ok=1,num,tt=0; int res=0; while(t<n){ vector<int>temp; num=0; for(int i=1;i<=n;i++){ if(!vis[i]&&v[i]==0){ num++; vis[i]=1; temp.push_back(i); } } for(int i=0;i<temp.size();i++){ for(int j=0;j<M[temp[i]].size();j++) if(!vis[M[temp[i]][j]] )v[M[temp[i]][j]]--; } if(num==0){ok=0;break;} res+=(888+tt)*num;tt++; t+=num; //cout<<"t="<<t<<endl; } if(!ok){ printf("-1\n"); continue; } printf("%d\n",res); }}
0 0
- HDU 2647 Reward(拓扑排序)
- hdu 2647 Reward (拓扑排序)
- hdu 2647 Reward ( 拓扑排序 )
- HDU 2647 - Reward(拓扑排序)
- hdu 2647 Reward (拓扑排序)
- HDU 2647Reward(拓扑排序)
- HDU 2647 Reward(图论-拓扑排序)
- HDU 2647 Reward(图论-拓扑排序)
- HDU 2647 Reward(拓扑排序)
- HDU 2647 -- Reward (拓扑排序)
- hdu 2647 Reward(拓扑排序)
- HDU-2647 Reward(拓扑排序)
- HDU 2647Reward (拓扑排序)
- HDU 2647 Reward(拓扑排序)
- HDU 2647 Reward(拓扑排序)
- HDU 2647 Reward(拓扑排序)
- HDU 2647 Reward (拓扑排序)
- HDU 2647 Reward(拓扑排序)
- Bellman-ford模板
- HDU 1317 XYZZY
- HDU 1535 Invitation Cards
- HDU 3339 In Action
- IOS获取系统通讯录联系人信息
- HDU 2647 Reward(拓扑排序)
- 栈的应用--括号匹配的检验(C++)
- HDU 5055 Bob and math problem
- Toast提示内容简单介绍
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU 2962 Trucking
- A Mathematical Curiosity
- HDU2771 Stealing Harry Potter\'s Precious(bfs+dfs)
- do-while随机求十个数的和