给你一个4个点的环,问你从2号点出发, 再回到2号点,长度>=K的最短路是多少。环上的边长度不超过30000。

跑出来所有dis(2,j)以后,然后for一遍j,根据dis(2,j)+t*2*w>=K,解出来对于每个j而言最小的t,然后尝试更新答案即可。如果dis(2,j)已经大于等于K了,那直接用其尝试更新答案。

跟CDOJ1633很像。

#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
ll ans,K;
int W,T,a[4];
typedef pair<int,int> Point;
queue<Point>q;
bool inq[4][60010];
int dis[4][60010];
void spfa()
{
memset(dis,0x7f,sizeof(dis));
memset(inq,0,sizeof(inq));
q.push(make_pair(1,0)); inq[1][0]=1; dis[1][0]=0;
while(!q.empty()){
Point U=q.front();
Point V=make_pair((U.first+1)%4,(U.second+a[U.first])%(2*W));
if(dis[V.first][V.second]>dis[U.first][U.second]+a[U.first]){
dis[V.first][V.second]=dis[U.first][U.second]+a[U.first];
if(!inq[V.first][V.second]){
q.push(V);
inq[V.first][V.second]=1;
}
}
V=make_pair((U.first+3)%4,(U.second+a[(U.first+3)%4])%(2*W));
if(dis[V.first][V.second]>dis[U.first][U.second]+a[(U.first+3)%4]){
dis[V.first][V.second]=dis[U.first][U.second]+a[(U.first+3)%4];
if(!inq[V.first][V.second]){
q.push(V);
inq[V.first][V.second]=1;
}
}
q.pop();
inq[U.first][U.second]=0;
}
}
int main(){
// freopen("1005.in","r",stdin);
// freopen("1005.out","w",stdout);
scanf("%d",&T);
for(;T;--T){
ans=9000000000000000000ll;
scanf("%lld",&K);
for(int i=0;i<4;++i){
scanf("%d",&a[i]);
}
W=min(a[1],a[0]);
spfa();
for(int i=0;i<2*W;++i){
if(dis[1][i]<2000000000){
// printf("%d: (%d)\n",i,dis[1][i]);
if(dis[1][i]<K){
ans=min(ans,(ll)dis[1][i]+(ll)(2*W)*((K-(ll)dis[1][i])/(ll)(2*W)+(ll)((K-(ll)dis[1][i])%(ll)(2*W)!=0)));
}
else{
ans=min(ans,(ll)dis[1][i]);
}
}
}
printf("%lld\n",ans);
}
return 0;
}

【最短路】【spfa】hdu6071 Lazy Running的更多相关文章

  1. 2017 Multi-University Training Contest - Team 4 hdu6071 Lazy Running

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6071 题目: Lazy Running Time Limit: 2000/1000 MS (J ...

  2. hdu-6071 Lazy Running

    In HDU, you have to run along the campus for 24 times, or you will fail in PE. According to the rule ...

  3. HDU 6071 Lazy Running (同余最短路)

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

  4. 多校4 lazy running (最短路)

    lazy running(最短路) 题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\) ...

  5. HDU 6071 Lazy Running (同余最短路 dij)

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

  6. hdu 6071 Lazy Running 最短路建模

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) P ...

  7. HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4

    /* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...

  8. 最短路模板(Dijkstra & Dijkstra算法+堆优化 & bellman_ford & 单源最短路SPFA)

    关于几个的区别和联系:http://www.cnblogs.com/zswbky/p/5432353.html d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到 ...

  9. HDU 6071 同余最短路 spfa

    Lazy Running Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)To ...

随机推荐

  1. window对象的方法和属性汇总

    window对象有以下方法: open close alert confirm prompt setTimeout clearTimeout setInterval clearInterval mov ...

  2. [CTF技巧]批量连接SSH批量执行命令

    https://files.cnblogs.com/files/nul1/autossh1.3.jar.zip 下载下来以后直接将后缀去除就好了. 比赛的时候可以批量写一个不死马然后你懂的. Linu ...

  3. sql 自定义split

    以下数据库操作针对sql server. 问题来源:由于项目中,有的表字段内容是由多个id或多个其他内容拼接而成.(如:'1,2,3,4,5',或者'name_age_school'),特点是都用某个 ...

  4. Linux内核堆栈使用方法 进程0和进程1【转】

    转自:http://blog.csdn.net/yihaolovem/article/details/37119971 目录(?)[-] 8 Linux 系统中堆栈的使用方法 81  初始化阶段 82 ...

  5. Laravel 项目上线的一些注意事项

    1.应用生产环境 在 .env 文件里设置 APP_ENV=production 2.关闭调试模式 在 .env 文件中设置 APP_DEBUG = false 3.生成 APP_KEY 使用 Art ...

  6. 【uva11613】生产销售规划

    这很像之前做的一道noip模拟题…… 所以当时那题也可以用费用流写(雾) 拆点,将每个月拆成两个点,一个向起点连边表示产量,另一个点连汇点表示销量. 然后每个点依次往后面的点2连边,表示保存. #in ...

  7. Canvas 高级

    一.Canvas 高级 1.变换--位移 translate(x, y) 2.变换-缩放 scale(xS, yS) 3.变换-旋转 rotate(弧度) 4.环境的保存和释放 save() rest ...

  8. 关于aspxgridview里面过长内容只显示的一部分的处理方案

    protected void g_Message_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventAr ...

  9. python 使用国内源安装软件

    python linux 等 使用国内源安装软件 速度更快 你值得拥有 ! 豆瓣源:pip install -i https://pypi.douban.com/simple/ 阿里源:pip ins ...

  10. P2885

    2885 code[class*="language-"] { padding: .1em; border-radius: .3em; white-space: normal; b ...