博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 6071 Lazy Running (同余最短路 dij)
阅读量:5772 次
发布时间:2019-06-18

本文共 2895 字,大约阅读时间需要 9 分钟。

Lazy Running

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1384    Accepted Submission(s): 597

Problem Description
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 are 4 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 these 4 checkpoints as a circle. When you are at checkpoint pi, you can just run to pi1 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.
Checkpoint p2 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.
 

 

Input
The first line of the input contains an integer 
T(1T15), denoting the number of test cases.
In each test case, there are 5 integers K,d1,2,d2,3,d3,4,d4,1(1K1018,1d30000), denoting the required distance and the distance between every two adjacent checkpoints.
 

 

Output
For each test case, print a single line containing an integer, denoting the minimum distance.
 

 

Sample Input
1 2000 600 650 535 380
 

 

Sample Output
2165
Hint
The best path is 2-1-4-3-2.
 

 

Source
【题意】四个点连成环,相邻两个点之间有距离,问从点 1 出发回到点1 ,总距离超过K 的最短路是多少。
【分析】像这种无限走下去的题,可以用同余最短路来解。点1相邻的两条边,设最短的那条长度为,m,那么存在一条长度为x的回到1节点的路,就一定存在长度为x+2*m的路。
  dis[i][j]表示到达i点总长度%2*m==j的最短路,然后dij就行了。
 
#include 
#define inf 0x3f3f3f3f#define met(a,b) memset(a,b,sizeof a)#define pb push_back#define mp make_pair#define rep(i,l,r) for(int i=(l);i<=(r);++i)#define inf 0x3f3f3f3fusing namespace std;typedef long long ll;const int N = 6e4+50;;const int M = 255;const int mod = 19260817;const int mo=123;const double pi= acos(-1.0);typedef pair
pii;typedef pair
P;int n,s;ll dis[6][N];ll k,edg[6][6],m,ans;void dij(int s){ priority_queue

,greater

>q; for(int i=0;i<4;i++){ for(int j=0;j<=m;j++){ dis[i][j]=1e18; } } q.push(P(0LL,s)); while(!q.empty()){ ll w=q.top().first; int u=q.top().second; q.pop(); if(u==s){ if(w

d){ dis[i][d%m]=d; q.push(P(d,i)); } } }}int main(){ int T; scanf("%d",&T); while(T--){ ans=1e18; scanf("%lld",&k); for(int i=0;i<4;i++){ scanf("%lld",&edg[i][(i+1)%4]); edg[(i+1)%4][i]=edg[i][(i+1)%4]; } m=2*min(edg[1][0],edg[1][2]); ans=((k-1)/m+1)*m; dij(1); printf("%lld\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/jianrenfang/p/7599448.html

你可能感兴趣的文章
FreeNAS8 ISCSI target & initiator for linux/windows
查看>>
Rainbond 5.0.4版本发布-做最好用的云应用操作系统
查看>>
Java判断是否为垃圾_Java GC如何判断对象是否为垃圾
查看>>
多项式前k项和java_多项式朴素贝叶斯softmax改变
查看>>
java数组只能交换0下标和n_编程练习-只用0交换排序数组
查看>>
OracleLinux安装说明
查看>>
标准与扩展ACL 、 命名ACL 、 总结和答疑
查看>>
使用@media实现IE hack的方法
查看>>
oracle体系结构
查看>>
Microsoft Exchange Server 2010与Office 365混合部署升级到Exchange Server 2016混合部署汇总...
查看>>
Proxy服务器配置_Squid
查看>>
【SDN】Openflow协议中对LLDP算法的理解--如何判断非OF区域的存在
查看>>
纯DIV+CSS简单实现Tab选项卡左右切换效果
查看>>
Centos7同时运行多个Tomcat
查看>>
使用CocoaPods过程中的几个问题
查看>>
Spring boot 整合CXF webservice 全部被拦截的问题
查看>>
Pinpoint跨节点统计失败
查看>>
机房带宽暴涨问题分析及解决方法
查看>>
XP 安装ORACLE
查看>>
八、 vSphere 6.7 U1(八):分布式交换机配置(vMotion迁移网段)
查看>>