2017多校第4场 HDU 6071 Lazy Running 同余最短路
来源:互联网 发布:jsp中引用js文件 编辑:程序博客网 时间:2024/06/05 04:21
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6071
题意:给你一个由四个节点组成的环,求从节点2出发,回到节点2的不小于k的最短路。
解法:见ICPCCAMP上面这个题:点击打开链接 有叉姐的强力回答。那个题和这个是一样的思路。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const LL inf = 1e16;const int maxn=5;int T,d1,d2,d3,d4,n,s;LL k,m;struct edge{ int v; LL w;};vector<edge>g[maxn];LL dp[4][70000];void Dijstra(int s){ priority_queue<pair<LL,int>,vector<pair<LL,int> >, greater<pair<LL, int>> >q; for(int i=0; i<4; i++) for(int j=0; j<m; j++) dp[i][j]=inf; dp[s][0]=0; q.push(make_pair(0,s)); while(!q.empty()) { LL d=q.top().first; int u=q.top().second; q.pop(); if(d>dp[u][d%m]) continue; for(int i=0; i<g[u].size(); i++){ int v=g[u][i].v; LL dis = d+g[u][i].w; if(dp[v][dis%m]>dis){ dp[v][dis%m]=dis; q.push(make_pair(dis,v)); } } }}int main(){ scanf("%d", &T); while(T--) { n=4; s=1; for(int i=0; i<4; i++) g[i].clear(); scanf("%lld%d%d%d%d",&k,&d1,&d2,&d3,&d4); g[0].push_back(edge{1,1LL*d1}); g[1].push_back(edge{0,1LL*d1}); g[1].push_back(edge{2,1LL*d2}); g[2].push_back(edge{1,1LL*d2}); g[2].push_back(edge{3,1LL*d3}); g[3].push_back(edge{2,1LL*d3}); g[3].push_back(edge{0,1LL*d4}); g[0].push_back(edge{3,1LL*d4}); m = min(1LL*d1, 1LL*d2) * 2; Dijstra(s); // puts("fuck"); LL ans = 1e19; for(int i=0; i<m; i++){ LL temp = k-dp[1][i]; if(temp<=0) ans=min(ans,dp[1][i]); else ans=min(ans,dp[1][i]+temp/m*m+(temp%m>0)*m); } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- 2017多校第4场 HDU 6071 Lazy Running 同余最短路
- HDU 6071 Lazy Running(同余+最短路)
- HDU 6071 Lazy Running(同余最短路)
- HDU 6071 Lazy Running 同余 + 最短路
- HDU 6071 Lazy Running(同余最短路)
- Hdu 6071 Lazy Running【同余最短路】
- HDU 6071 Lazy Running(模同余最短路)
- hdu 6071 Lazy Running(spfa+同余最短路)
- 2017多校四 1005题 hdu 6071 Lazy Running 同余类 最短路
- 2017年多校赛第四场 1005 Lazy Running(同余最短路)
- hdu6071-最短路&思维&多校4&同余-Lazy Running
- Hdu-6071 Lazy Running(trick最短路)
- HDU6071Lazy Running(同余最短路)
- 同余最短路
- 同余最短路
- HDU6071 Lazy Running【最短路】
- HDU6071-Lazy Running 最短路+思维
- POJ6071 Lazy Running(最短路)
- Mat数据结构
- poj 1797 Heavy Transportation 最短路 dijkstra
- 白话经典算法系列之六 快速排序 快速搞定
- 【数论-莫比乌斯】hdu 6053 TrickGCD
- 异步任务
- 2017多校第4场 HDU 6071 Lazy Running 同余最短路
- 关于使用markdown的一点心得
- hdu3938(离线并查集)
- 三分-HDU3714
- 小白、教你学C++(8)异常处理结构层次
- (CodeChef
- 旋转变换(一)旋转矩阵
- 烦人的ppt
- j2me 游戏开发详解