SRM675(div2) Level Two ShortestPathWithMagic
来源:互联网 发布:使用java程序录音 编辑:程序博客网 时间:2024/06/07 16:19
SRM675(div2) Level Two ShortestPathWithMagic
Problem Statement
Problem Statement for ShortestPathWithMagic
Problem Statement
There are n cities, numbered from 0 to n-1. It is possible to travel directly between any two cities. Different pairs of cities may require different travel times. You are given the travel times as a String[] dist with n elements, each consisting of n digits. The digit dist[i][j] represents the time needed to travel between cities i and j in either direction.You are also given an int k. You have k magic potions. The potion makes you twice as fast as you normally are. Each time you travel (directly) from some city to some other city, you may take one of the potions. If you do, that travel will only take half of what it normally would. You are not allowed to take more than one potion at the same time. You are not required to drink all potions you have.
Compute and return the smallest amount of time in which you can travel from city 0 to city 1.
Definition
Class:ShortestPathWithMagicMethod:getTimeParameters:String[], intReturns:doubleMethod signature:double getTime(String[] dist, int k)(be sure your method is public)Notes
-The travel times given in dist don't have to satisfy the triangle inequality.-Your return value must have a relative or absolute error less than 1e-9Constraints
-dist will contain between 2 and 50 elements, inclusive.-Each string in dist will contain exactly |dist| characters.-Each character in dist will be between '0' and '9', inclusive.-For any valid i and j: dist[i][j] = dist[j][i].-For any valid i: dist[i][i] = 0.-k will be between 0 and 50, inclusive.Examples
0){"094", "904", "440"}
1
Returns: 4.5According to dist, you need:
- 9 units of time to travel between cities 0 and 1
- 4 units of time to travel between cities 0 and 2
- 4 units of time to travel between cities 1 and 2
{"094", "904", "440"}
2
Returns: 4.0The normal travel times are the same as in Example 0, but now you have two magic potions. This changes the optimal solution. Now it is better to travel from 0 to 2 and then from 2 to 1. For each segment of your trip you will drink one of the potions. Thus, each segment will only take 4/2 = 2 units of time.2)
{"094", "904", "440"}
50
Returns: 4.0You are not allowed to use more than one potion at the same time. The optimal solution remains the same as in Example 1, only now you will still have 48 magic potions when you reach city 1.3)
{"094", "904", "440"}
0
Returns: 8.0
4)
{"076237", "708937", "680641", "296059", "334508", "771980"}
1
Returns: 3.55)
{"00", "00"}
50
Returns: 0.0
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
This problem was used for:Single Round Match 675 Round 1 - Division II, Level Two
题意:给你一个邻接表,求最短距离,但是有k次机会可以使边的距离减半,求从0带1的距离
先用Floyd求出任意两点间的最短距离
dp[k][i][j]表示有从i到j,有k次机会是距离减半的最短距离
n表示结点个数
a[i][j]表示从i到j的直接距离
然后用dp,转移方程dp[k][i][j] = min(dp[k][i][j], a[i][con]/2 + dp[k-1][con][j]);(0<=i,j,con<n )
dp好久都没写的都忘了!!!
0 0
- SRM675(div2) Level Two ShortestPathWithMagic
- SRM675(div2) Level OneLengthUnitCalculator
- SRM675 medium ShortestPathWithMagic(DP+Dijkstra)
- SRM675 div2 hard TreeAndPathLength2(DP)
- TopCoder SRM DIV2 Level 3: RelativelyPrimeSubset
- TopCoder SRM 558 DIV2 Level 3:CatAndRabbit
- topcoder srm 451 div2 level 3 PizzaDelivery
- TopCoder SRM 664 Div2 Level One
- TopCoder SRM 664 Div2 Level Three
- B. Two Buttons(Codeforces Round #295(div2))
- Codeforces 295 Div2 B.Two Buttons
- CF--333--div2--A.Two Bases
- Two Part: Level 90 Heuksal In SRO
- 两级页表(Two-Level Page Table)
- linux shell two-level de-reference
- SRM 582 Div II Level Two SpaceWarDiv2
- SRM 583 Div Level Two:IDNumberVerification
- Test SRM Level Two: CountExpressions, Brute Force
- 用PS制作燃烧的火焰人物
- window curl
- 文件读写操作
- 【Android入门】第一个程序运行出现AVD Error错误
- 把String[] 转换为String的工具类总结
- SRM675(div2) Level Two ShortestPathWithMagic
- python拾遗(二) python语法
- (ZT) cout打印不了函数地址
- Codeforces Round #335 (Div. 2) [补E]
- Java Socket(三) URL的应用
- 应用中的「确定」按钮应该在左边还是右边?
- bzoj1059[ZJOI2007]矩阵游戏
- java clone和深度复制和浅复制的个人总结
- mysql操作脚本总结