2017 icpc Southeast USA J 题 Gym
来源:互联网 发布:简单软件的c语言程序 编辑:程序博客网 时间:2024/06/06 05:24
题意:
给出n个点,m条边,每一条边需要花 k 天才能走完,第一天的时候这个人在点 1
每一个点在第一天的时候有权值 g ,然后按照每天减少 d 天的速度减少,最多减少到零
题解:
广搜:从第一个点开始,对它周围的所有点进行遍历,依次类推
但普通广搜会爆掉,这里剪枝需要对题意有深刻的理解:我们发现,一个图里面某一天到某一个点方式有很多种方式,如果同一天在同一个点的这样的情况都搜索下去明显多了很多没有必要的东西,因此记忆一下,同一天到同一个点的选了权值大的权值小的就不要继续搜索了(所以在优先队列里面我们对时间进行排序)
下面的代码其实还可以继续剪枝,随时间的流逝,所有点都变成0的时候我们就不用继续搜索了
#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;const int maxn = 1000+5;int tot,n,m,ans;int head[maxn];int g[maxn],d[maxn];int dis[maxn][maxn];struct Node{ int v,w,next;}e[2*maxn];struct node{ int id,val,day; bool operator< (const node& rhs) const{ return day>rhs.day; }};void addEdge(int u,int v,int w){ e[tot].v = v; e[tot].w = w; e[tot].next = head[u]; head[u] = tot++;}void bfs(){ memset(dis,0,sizeof(dis)); priority_queue<node> q; node p; p.id = 1; p.val = g[1]; p.day = 1; q.push(p); ans = g[1]; dis[1][1] = g[1]; while(!q.empty()) { p = q.top(); q.pop(); int u = p.id; for(int i=head[u];i!=-1;i=e[i].next) { int v = e[i].v; int w = e[i].w; node tmp = p; tmp.id = v; tmp.val += max(0,g[v]-d[v]*(p.day+w-1)); tmp.day = p.day + w; if(tmp.val<=dis[v][tmp.day]) continue; dis[v][tmp.day] = tmp.val; q.push(tmp); ans = max(ans,tmp.val); } }}int main(){ //freopen("in.txt","r",stdin); while(~scanf("%d%d",&n,&m)) { tot = 0; memset(head,-1,sizeof(head)); for(int i=1;i<=n;i++) scanf("%d%d",&g[i],&d[i]); while(m--) { int u,v,w; scanf("%d%d%d",&u,&v,&w); addEdge(u,v,w); addEdge(v,u,w); } bfs(); printf("%d\n",ans); } return 0;}
阅读全文
0 0
- 2017 icpc Southeast USA J 题 Gym
- 2017 icpc Southeast USA D 题 Gym
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1) J.Treasure Map dp
- 【Author : DS】{Regionals 2011, North America - Southeast USA} C题解题报告
- hihoCoder 1636(2017北京icpc-j题)
- GYM 100685 J【交互题】
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1) F.Move Away 几何
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1) H.Security Badges 区间双重合
- 2017icpc-beijing-j(pangu and stone)
- 2015 Asia Singapore ICPC Contest J题
- Gym 100917 J. Judgement
- Gym-100712J-Candy
- Gym 100712J Candy
- Gym 100637J
- Gym 101147.J
- Gym 101243.J
- Gym 101246.J
- Gym 101343.J
- SpringMVC中@Controller和@RequestMapping用法和其他常用注解
- 【算法】算法分析与设计的基本方法
- 去掉EditText的默认焦点
- 用IOT的思维来管理我们的查看我们重要业务的服务器健康状态-Azure配置篇!
- Android开发中线程和线程池的使用
- 2017 icpc Southeast USA J 题 Gym
- Exception自定义处理
- <body>标签中onload方法与 Jquery库函数 $(selector).ready()比较
- python_subprocess_unity
- Mac sierra下 wget安装
- __attribute__((constructor))和__attribute__((destructor))
- eclipse中maven项目不显示Maven Dependencies依赖
- 2017.12.13学习总结
- Solr_集群介绍