hdu 6071 Lazy Running 最短路建模
Lazy Running
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
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 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.
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.
In each test case, there are 5 integers K,d1,2,d2,3,d3,4,d4,1(1≤K≤1018,1≤d≤30000), denoting the required distance and the distance between every two adjacent checkpoints.
2000 600 650 535 380
The best path is 2-1-4-3-2.
友情链接:https://post.icpc-camp.org/d/674-poi-x-sums
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-4
#define bug(x) cout<<"bug"<<x<<endl;
const int N=6e4+,M=1e6+,inf=1e9+,MOD=1e9+;
const LL INF=1e18+,mod=1e9+; struct mmp
{
int s;
LL dis;
bool operator <(const mmp &b)const
{
return dis>b.dis;
}
};
LL ans[][N];
int vis[][N];
priority_queue<mmp>q;
vector<pair<int,int> >edge[];
void dij(int s,int m)
{
ans[s][]=;
q.push((mmp){s,0LL});
while(!q.empty())
{
mmp now = q.top();
q.pop();
if(vis[now.s][now.dis%m])continue;
vis[now.s][now.dis%m]=;
for(int i = ; i < ; i++)
{
int v=edge[now.s][i].first;
int w=edge[now.s][i].second;
int z=(now.dis+w)%m;
if(ans[v][z]==-||ans[v][z] >=now.dis + w)
{
q.push((mmp){v,now.dis+w});
ans[v][z]=now.dis+w;
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(ans,-,sizeof(ans));
memset(vis,,sizeof(vis));
LL x;
int d1,d2,d3,d4;
scanf("%lld%d%d%d%d",&x,&d1,&d2,&d3,&d4);
for(int i=;i<=;i++)
edge[i].clear();
edge[].push_back(make_pair(,d1));
edge[].push_back(make_pair(,d4));
edge[].push_back(make_pair(,d1));
edge[].push_back(make_pair(,d2));
edge[].push_back(make_pair(,d3));
edge[].push_back(make_pair(,d2));
edge[].push_back(make_pair(,d3));
edge[].push_back(make_pair(,d4));
dij(,*d1);
LL out=INF;
d1*=;
for(int i=;i<d1;i++)
{
if(ans[][i]==-)continue;
if(ans[][i]>=x)out=min(out,ans[][i]);
else
{
LL z=x-ans[][i];
LL zz=ans[][i]+(z%d1?(z/d1+)*d1:z);
out=min(out,zz);
}
}
printf("%lld\n",out);
}
return ;
}
hdu 6071 Lazy Running 最短路建模的更多相关文章
- HDU 6071 Lazy Running (最短路)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6071 题解 又是一道虐信心的智商题... 首先有一个辅助问题,这道题转化了一波之后就会化成这个问题: ...
- HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4
/* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...
- HDU 6071 Lazy Running (同余最短路 dij)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- HDU 6071 Lazy Running (同余最短路)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- HDU 6071 Lazy Running(很牛逼的最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=6071 题意: 1.2.3.4四个点依次形成一个环,现在有个人从2结点出发,每次可以往它相邻的两个结点跑,求最后回 ...
- 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 之间有路相连, 现在 ...
- 多校4 lazy running (最短路)
lazy running(最短路) 题意: 一个环上有四个点,从点2出发回到起点,走过的距离不小于K的最短距离是多少 \(K <= 10^{18} 1 <= d <= 30000\) ...
- HDU 6071 同余最短路 spfa
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- 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 ...
随机推荐
- 问题 1084: 用筛法求之N内的素数。
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- jumpserver堡垒机安装
1. 下载jumpserver cd /opt wget https://github.com/jumpserver/jumpserver/archive/master.zip unzip maste ...
- SQL Server char,varchar,nchar,nvarchar区别
SQL Server char,varchar,nchar,nvarchar区别 (1) 定义: char: 固定长度,存储ANSI字符,不足的补英文半角空格. nchar: 固 ...
- jboss 报错处理及端口修改
执行文件 ./shutdown.sh -S 后 重启jboss 执行 ./run.sh -Djboss.bind.address=192.168.132.129 & 如果一台机器安装多个jbo ...
- Python小项目四:实现简单的web服务器
https://blog.csdn.net/u010103202/article/details/74002538 本博客是整理在学习实验楼的课程过程中记录下的笔记形成的,参考:https://www ...
- Java笔记 #03# HtmlUnit爬虫
存档留用 (= 存档留着备用) 爬的是一个开放的自动回复机器人 API 网站 http://i.itpk.cn/. 结构 大致如下: 我做的事情就是[输入文字,点击按钮,爬取内容],如上图所示. pa ...
- linux中权限对文件和目录的意义
1.权限对文件的意义: 读:可查看文件的内容 写:可修改文件的内容(但不能删除文件) 执行:可执行文件 2.权限对目录的意义: 读:可以查看目录下的内容,即可以读取该目录下的结构列表 写:可修改目录下 ...
- 【ASP.Net MVC3 】使用Unity 实现依赖注入
转载于:http://www.cnblogs.com/techborther/archive/2012/01/06/2313498.html 家人身体不太好,好几天没在园子里发帖了. 新项目还是要用M ...
- 集合框架-Collection与List集合
对象数组的内存图解: 集合的继承体系图解: * 数组和集合的区别? * A:长度区别 * 数组的长度固定 * 集合长度可变 * B:内容不同 * 数组存储的是同一种类型的元素 * 而集合可以存储不同类 ...
- PyCharm笔记之首次安装和激活
转载:http://www.cnblogs.com/Ivyli4258/p/7440147.html PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其 ...