地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6071

题目:

Lazy Running

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 144    Accepted Submission(s): 62

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

 
Input
The first line of the input contains an integer T(1≤T≤15), denoting the number of test cases.

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.

 
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
 
思路:
  一道做过类似题的题目,在比赛时想了半个小时都没想出来,然后就做别的题去了。
  做过的题还不会做,好气啊
  记w为2和相邻节点路径的最小值,则如果存在一条从2出发,从2结束的路径(长度为x),那么x+w*2也必然是合法的。(这里的w取相邻节点路径的最小值是为了优化时间,不取最小值也可以)
  所以d[i][x]记为到达i节点且路径长度模2*w为x的最短路径长度。求出d[2][x]数组后就可以通过枚举x得到答案。
  那为什么这样做是对的呢?
  因为到达2的所有模2*w的剩余系的最短路径长度都被考虑了,所以答案必然是正确的。
 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,d12,d23,d34,d41;;
LL d[][],dk,p;
vector<PII>mp[];
void spfa(void)
{
queue<pair<LL,LL>>q;
for(int i=;i<=;i++)
for(int j=;j<p;j++)
d[i][j]=2e18;
q.push(MP(2LL,0LL));
while(q.size())
{
LL u=q.front().first,w=q.front().second;
q.pop();
if(w>dk*)continue;
for(auto v:mp[u])
if(d[v.first][(w+v.second)%p]>w+v.second)
{
d[v.first][(w+v.second)%p]=w+v.second;
q.push(MP(v.first,w+v.second));
}
}
}
int main(void)
{
int t;cin>>t;
while(t--)
{
memset(mp,,sizeof mp);
scanf("%lld%d%d%d%d",&dk,&d12,&d23,&d34,&d41);
mp[].PB(MP(,d12)),mp[].PB(MP(,d41));
mp[].PB(MP(,d12)),mp[].PB(MP(,d23));
mp[].PB(MP(,d23)),mp[].PB(MP(,d34));
mp[].PB(MP(,d34)),mp[].PB(MP(,d41));
p=2LL*min(d12,d23);
spfa();
LL ans=2e18;
for(int i=;i<p;i++)
if(d[][i]>=dk)
ans=min(d[][i],ans);
else
ans=min((dk-d[][i]+p-)/p*p+d[][i],ans);
printf("%lld\n",ans);
}
return ;
}

2017 Multi-University Training Contest - Team 4 hdu6071 Lazy Running的更多相关文章

  1. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  3. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  4. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  5. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  8. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. ItcastOA_整体说明_准备环境

    1. 整体说明 1.1. 项目说明 1.1.1. OA概述 OA是Office Automation的缩写,本意为利用技术的手段提高办公的效率,进而实现办公的自动化处理.实现信息化.无纸化办公,可方便 ...

  2. 编程之美 set 21 24点游戏

    题目 输入: n1, n2, n3, n4 (1~13) 输出: 若能得到运算结果为 24, 则输出一个对应的运算表达式 如: 输入: 11, 8, 3, 5 输出: (11-8) * (3*5) = ...

  3. 剑指 offer set 26 不用加减乘除做加法

    总结 1. Leetcode 上有一道题, 是不用乘除做乘法, 那道题算是背包问题的变形 2. 不用加减乘除, 还可以用移位操作 3. 将数字转成二进制格式, 然后运用二进制亦或, 移位运算解决 3. ...

  4. Net性能分析与调试培训资料

    https://wenku.baidu.com/view/76340ccc02d276a200292e51.html

  5. 使用pug(jade),以及在vue+webpack中使用pug(jade)

    一:在HTML中使用pug 在css中有预处理器less和scss来使我们的样式表更加的简介,那么在HTML中有没有这样的格式呢,答案是有的,那就是pug(前身是jade),效果如下: 转译以后 好, ...

  6. 深搜———ZOJ 1004:anagrams by stack

    细节问题各种虐!! 其实就是简单的一个深搜 看成二叉树来理解:每个节点有两个枝:入栈和出栈. 剪枝操作:只有当栈顶元素和当前位置的目标字符相同时才出栈,否则就不出栈 dfs写三个参数:depth搜索深 ...

  7. LAMP集群项目五 nfs存储的数据实时同步到backupserver

    tar fxzsersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/ mv GNU-Linux-x86 sersync cp sers ...

  8. Go语言 关键字:defer

    defer和go一样都是Go语言提供的关键字.defer用于资源的释放,会在函数返回之前进行调用.一般采用如下模式: f,err := os.Open(filename) if err != nil ...

  9. Laravel 5.x HTTPS反向代理的实现

    需求 可针对多个域名设置HTTPS并指向到同一个项目. 最先考虑到的是通过nginx的反向代理来实现,最终测试发现效果并不完美. 示例如下: server { listen 127.0.0.1:808 ...

  10. 关于HashSet在 java7 与 java8的不同

    作者:RednaxelaFX链接:https://www.zhihu.com/question/28414001/answer/40733996来源:知乎著作权归作者所有.商业转载请联系作者获得授权, ...