Hdu-6071 Lazy Running(trick最短路)
来源:互联网 发布:西贝柳斯软件配置 编辑:程序博客网 时间:2024/05/28 19:23
In HDU, you have to run along the campus for 24 times, or you will fail in PE. According to the rule, you must keep your speed, and your running distance should not be less than K meters.
There are4 checkpoints in the campus, indexed as p1,p2,p3 and p4 . Every time you pass a checkpoint, you should swipe your card, then the distance between this checkpoint and the last checkpoint you passed will be added to your total distance.
The system regards these4 checkpoints as a circle. When you are at checkpoint pi , you can just run to pi−1 or pi+1 (p1 is also next to p4 ). You can run more distance between two adjacent checkpoints, but only the distance saved at the system will be counted.
Checkpointp2 is the nearest to the dormitory, Little Q always starts and ends running at this checkpoint. Please write a program to help Little Q find the shortest path whose total distance is not less than K .
There are
The system regards these
Checkpoint
In each test case, there are
12000 600 650 535 380
2165
The best path is 2-1-4-3-2.
分析:比赛的时候没开这道题,但是其实以前做过类似的题,假如存在一个最优解x,那么x+2*d(2,3)一定也是一个解,那么重新构图,把一个点按起点到其距离对2*d(2,3)取模拆分成最多60000个点,然后再在这个图上跑最短路就可以了.
#include <bits/stdc++.h>using namespace std;const long long INF = 2000000000000000000ll;typedef pair<int,long long> pii;typedef long long ll;int T;ll K,x,w,ans,d[5][60005];bool vis[5][60005];pii q[4*60005];vector<pii> G[5];ll deal(ll x){ if(x >= K) return x; ll temp = (K-x)/w; if((K-x) % w) temp++; return x + temp*w;}int main(){ scanf("%d",&T); while(T--) { ans = INF; memset(d,0x3f,sizeof(d)); memset(vis,0,sizeof(vis)); for(int i = 1;i <= 4;i++) G[i].clear(); scanf("%lld",&K); for(int i = 1;i <= 4;i++) { scanf("%lld",&x); G[i].push_back(make_pair(i % 4 + 1,x)); G[i % 4 + 1].push_back(make_pair(i,x)); } w = G[2][0].second*2; d[2][0] = 0; int s = 0,t = 0; q[t++] = make_pair(2,0); vis[2][0] = true; while(s != t) { pii it = q[s++]; int u = it.first;ll mod = it.second; for(pii temp : G[u]) { int v = temp.first;ll val = temp.second; if(d[v][(mod + val) % w] > d[u][mod] + val) { d[v][(mod + val) % w] = d[u][mod] + val; if(!vis[v][(mod + val) % w]) { vis[v][(mod + val) % w] = true; q[t++] = make_pair(v,(mod + val) % w); } } } vis[u][mod] = false; } for(int i = 0;i < w;i++) ans = min(ans,deal(d[2][i])); cout<<ans<<endl; }}
阅读全文
0 0
- Hdu-6071 Lazy Running(trick最短路)
- 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+同余最短路)
- HDU6071 Lazy Running【最短路】
- 2017多校第4场 HDU 6071 Lazy Running 同余最短路
- 2017多校四 1005题 hdu 6071 Lazy Running 同余类 最短路
- HDU6071-Lazy Running 最短路+思维
- POJ6071 Lazy Running(最短路)
- HDU6070 Lazy Running (最短路)
- HDU 6071 Lazy Running
- HDU 6071 Lazy Running
- HDU 6071 Lazy Running
- hdu6071-最短路&思维&多校4&同余-Lazy Running
- 有序数组的合并
- python构造json格式的post请求访问flask server
- 网络篇二---linux常用网络指令
- 关键点和跟踪基础——learning opencv3第16章翻译 一
- rainyday.js 下雨效果插件使用方法
- Hdu-6071 Lazy Running(trick最短路)
- Access导入MDB文件
- HTML5_表单的补充、浮动框架、谷歌专用标签、高亮标签
- centos下的中文分词coreseek-4.1的编译安装与基本配置
- spring requestmapping produce consume
- Centos7 编译安装mysql5.6
- 全景图的各种制作方法~~
- Face The Right Way POJ
- 教你将CAD转成PDF黑白色