lazy running(最短路)

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

看完这道题,觉得这是个智力题,想了一想,无从下手啊

每次总是看完题解,就豁然开朗

其实之前做过一个类似的题,题目

但是根本想不到第一步, 选2w来转换啊,而且也不知道正确性啊

这类题要仔细理解一番

#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int> using namespace std;
const LL inf = 1e18;
const int N = 6e4 + 10;
int g[4][4];
int mod;
LL K;
LL dis[4][N];
int inq[4][N];
void spfa(){
for(int i = 0;i < 4;i++){
for(int j = 0;j < mod;j++) {
dis[i][j] = inf,inq[i][j] = 0;
}
}
queue<P> q;
dis[1][0] = 0,inq[1][0] = 0;
q.push(P(1,0));
while(!q.empty()){
P cur = q.front();q.pop();
for(int i = -1;i <= 2;i+=2){
int x = (cur.first + i + 4)%4, y = (cur.second + g[cur.first][x])%mod;
if(dis[x][y] > dis[cur.first][cur.second] + g[cur.first][x]){
dis[x][y]= dis[cur.first][cur.second] + g[cur.first][x];
if(!inq[x][y]){
inq[x][y] = 1;
q.push(P(x,y));
}
}
}
}
}
int main()
{
int T;
cin>>T;
while(T--){
cin>>K;
for(int i = 0;i < 4;i++) {
scanf("%d",&g[i][(i+1)%4]);
g[(i+1)%4][i] = g[i][(i+1)%4];
}
mod = 2 * min(g[0][1],g[1][2]);
spfa();
LL ans = 2e18;
for(int i = 0;i < mod;i++){
LL d = K - dis[1][i];
ans = min(ans, dis[1][i] + (d + mod - 1) / mod * mod);
}
printf("%lld\n",ans);
}
return 0;
}

多校4 lazy running (最短路)的更多相关文章

  1. hdu 6071 Lazy Running 最短路建模

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

  2. HDU 6071 Lazy Running (最短路)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...

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

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

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

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

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

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

  6. 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 ...

  7. HDU 6071 Lazy Running(很牛逼的最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=6071 题意: 1.2.3.4四个点依次形成一个环,现在有个人从2结点出发,每次可以往它相邻的两个结点跑,求最后回 ...

  8. HDU 6071 Lazy Running(最短路)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6071 [题目大意] 给出四个点1,2,3,4,1和2,2和3,3和4,4和1 之间有路相连, 现在 ...

  9. 【最短路】【spfa】hdu6071 Lazy Running

    给你一个4个点的环,问你从2号点出发, 再回到2号点,长度>=K的最短路是多少.环上的边长度不超过30000. 跑出来所有dis(2,j)以后,然后for一遍j,根据dis(2,j)+t*2*w ...

随机推荐

  1. Java - 关于基础数据类型的形参和返回值

    1. 当基础数据类型被当作形参时,最好使用其包装类,因为这样可方便调用者传参(基础数据类型亦或是其包装类都可)   2. 当基础数据类型被当作返回值时,最好使用原型,因为这样可以方便调用者接收返回值( ...

  2. Servlet学习笔记06——什么是转发,路径,状态管理?

    1.include指令 (1)作用: 告诉容器,在将jsp转换成Servlet时,将 某个文件的内容插入到该指令所在的位置. (2)语法: <%@ include file="&quo ...

  3. django+xadmin在线教育平台(十)

    剩余app model注册 courses注册 新建courses/adminx.py: # encoding: utf-8 __author__ = 'mtianyan' __date__ = '2 ...

  4. php-5.6.26源代码 - opcode执行

    文件 php-5.6.26/Zend/zend_vm_execute.h ZEND_API void execute_ex(zend_execute_data *execute_data TSRMLS ...

  5. PHP审计(一)

    一.php中常见的危险函数和审计要点 危险函数(功能过于强大)    参数是否外部可控,有没有正确的过滤. PHP获取外界传入参数是通过下面几个全局函数的形式,所以审计参数传入经常要和下面几个变量打交 ...

  6. html页面 加载完成后再刷新 一次

    主要用于第一次加载页面有部分加载bug,再刷新一次即可正常运行. 简单粗暴直接上代码,不带参数,0影响 <Script>function refresh(){ url = location ...

  7. 裸机——I2C

    网上搜了些资料,碍于智商和基础,看不懂, 只有将S5PV210 数据手册关于I2C的部分,翻译记录下,留到以后用. 1.OVERVIEW The S5PV210 RISC microprocessor ...

  8. 笔记-falsk-入门-1

    笔记-falsk-入门-1 1.      前言 有几个概念需要解释下,WSGI,JINJA2,WERKZEUG Flask是典型的微框架,作为Web框架来说,它仅保留了核心功能:请求响应处理和模板渲 ...

  9. 笔记-爬虫-模拟登录github

    笔记-模拟登录github 1.      模拟登录github 1.1.    环境准备 安装/升级requests 2.20.0 pip install --upgrade requests pi ...

  10. 5-1 练习css 总结

    1. 边框 border:3px dotted; border: 2px solid yellow; 背景颜色 background-color: red; 外攘 margin:20px 0 20px ...