HDU 5965 Gym Class 贪心+toposort
分析:就是给一些拓补关系,然后求最大分数,所以贪心,大的越靠前越好,小的越靠后越好
剩下的就是toposort,当然由于贪心,所以使用优先队列
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long LL;
const int N=1e5+;
const int INF=0x3f3f3f3f;
const LL mod=1e9+;
priority_queue<int>q;
struct Edge{
int v,next;
}edge[N];
int head[N],tot;
void add(int u,int v){
edge[tot].v=v;
edge[tot].next=head[u];
head[u]=tot++;
}
int d[N];
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--){
// printf("Case #%d:\n",++cas);
int n,m;
scanf("%d%d",&n,&m);
memset(head,-,sizeof(head)),tot=;
memset(d,,sizeof(d));
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);++d[v];
}
while(!q.empty())q.pop();
for(int i=;i<=n;++i)
if(!d[i])q.push(i);
LL ans=;int cur=-;
while(!q.empty()){
int u=q.top();
q.pop();
if(cur==-)cur=u;
else cur=min(cur,u);
ans+=cur;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].v;
--d[v];
if(!d[v])q.push(v);
}
}
printf("%I64d\n",ans);
}
return ;
}
HDU 5965 Gym Class 贪心+toposort的更多相关文章
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- HDU 5695 ——Gym Class——————【贪心思想,拓扑排序】
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu-5695 Gym Class(贪心+拓扑排序)
题目链接: Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5835 Danganronpa (贪心)
Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
- HDU 5821 Ball (贪心)
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))
扫雷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- hdu 4004 (二分加贪心) 青蛙过河
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...
- Saving HDU(hdu2111,贪心)
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU - 5695 Gym Class 【拓扑排序】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5695 思路 给定一些关系 进行拓扑排序 但是有一个要求 对于哪些没有确切的位置的点 要按照ID大小 I ...
随机推荐
- iOS定位坐标转换工具-b
坐标系介绍 首先介绍一下目前的定位坐标系统1.地球坐标 :( 代号:GPS.WGS84 )--- 有W就是世界通用的也就是原始坐标体系,这是国际公认的世界标准坐标体系: 使用 WGS84 坐标系统的产 ...
- 2017年iOS应用将强制使用HTTPS安全加密-b
6月14日,WWDC 2016苹果开发者大会上,苹果在讲解全新的iOS10中提到了数据安全这一方面,并且苹果宣布iOS应用将从2017年1月起启用名为App Transport Security的安全 ...
- C#结合js 上传文件和删除文件(技术点有:asp.net mvc ,nhibernate,ajax等)
之前做项目的时候要用到上传文件的功能,现在我总结一下,上传文件和删除文件的代码,在以后的使用的过程中也更方便查找. [HttpPost] public ActionResult EditUser() ...
- MS Translator
在看白老师的书的时候看到的,现在MS已经开始转向服务,真对不同行业具有不同的服务,有些免费的,还是十分值得我们借用的,毕竟是大公司出来的产品,都会保证SLA的. 不多说了,直接上地址: https:/ ...
- nginx+ tomcat集群+动静资源分离
不知道为什么这个随便删不掉,写了也值显示一半一半不显示, 我把重新写了一遍: nginx + tomcat集群和动静资源分离
- ExtJS4.2学习(四)Grid表格中文排序问题(转)
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-07/173.html --------------- ...
- linux netstat命令使用详解
快速应用 netstat -lnp | more 显示监听的端口 简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),mas ...
- Unable to resolve target 'android-8'类似错误的解决办法
导入android项目出现:出现Unable to resolve target 'android-8'错误及其他的一些解决办法 - 为梦想而飞 - 博客频道 - CSDN.NEThttp://blo ...
- 列出man手册所有函数的方法
locate /man7/|sed -r 's#.*/([^/]+).7.gz$#\1#' locate /man7/ | xargs basename -a -s '.7.gz' apropos - ...
- hdu4639Hehe
http://acm.hdu.edu.cn/showproblem.php?pid=4639 统计连续he的数量恰为斐波序列 不同块进行相乘 #include <iostream> #i ...