Atomic Car Race - POJ 2744 dp
2014-09-22 12:19
204 查看
Atomic Car Race
Description
In the year 2020, a race of atomically energized cars will be held. Unlike today's car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully
plan where to change tires of their cars.
The race is a road race having n checkpoints in the course. Their distances from the start are a1, a2, ..., and an (in kilometers). The n-th checkpoint is the goal. At the i-th checkpoint (i < n), tires of a car can be changed. Of course, a team can choose
whether to change or not to change tires at each checkpoint. It takes b seconds to change tires (including overhead for braking and accelerating). There is no time loss at a checkpoint if a team chooses not to change tires.
A car cannot run fast for a while after a tire change, because the temperature of tires is lower than the designed optimum. After running long without any tire changes, on the other hand, a car cannot run fast because worn tires cannot grip the road surface
well. The time to run an interval of one kilometer from x to x + 1 is given by the following expression (in seconds). Here x is a nonnegative integer denoting the distance (in kilometers) from the latest checkpoint where tires are changed (or the start). r,
v, e and f are given constants.
1/(v - e * (x - r)) (if x >= r)
1/(v - f * (r - x)) (if x < r)
Your mission is to write a program to determine the best strategy of tire changes which minimizes the total time to the goal.
Input
The input consists of multiple datasets each corresponding to a race situation. The format of a
dataset is as follows.
n
a1 a2 . . . an
b
r v e f
The meaning of each of the input items is given in the problem statement. If an input line contains two or more input items, they are separated by a space.
n is a positive integer not exceeding 100. Each of a1, a2, ..., and an is a positive integer satisfying 0 < a1 < a2 < . . . < an <= 10000. b is a positive decimal fraction not exceeding 100.0. r is a nonnegative integer satisfying 0 <= r <= an - 1. Each of
v, e and f is a positive decimal fraction. You can assume that v - e * (an - 1 - r) >= 0.01 and v - f * r >= 0.01.
The end of the input is indicated by a line with a single zero.
Output
For each dataset in the input, one line containing a decimal fraction should be output. The decimal fraction should give the elapsed time at the goal (in seconds) when the best strategy is taken. An output line should not contain extra characters such as spaces.
The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.
Sample Input
Sample Output
题意:有n个换轮胎的服务点,一个新的轮胎从x到x+1需要的时间如公式所示,问到终点最短时间是多少。
思路:dp[i]表示在到达第i个站台需要的时间。
AC代码如下:
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 1194 | Accepted: 578 | Special Judge |
In the year 2020, a race of atomically energized cars will be held. Unlike today's car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully
plan where to change tires of their cars.
The race is a road race having n checkpoints in the course. Their distances from the start are a1, a2, ..., and an (in kilometers). The n-th checkpoint is the goal. At the i-th checkpoint (i < n), tires of a car can be changed. Of course, a team can choose
whether to change or not to change tires at each checkpoint. It takes b seconds to change tires (including overhead for braking and accelerating). There is no time loss at a checkpoint if a team chooses not to change tires.
A car cannot run fast for a while after a tire change, because the temperature of tires is lower than the designed optimum. After running long without any tire changes, on the other hand, a car cannot run fast because worn tires cannot grip the road surface
well. The time to run an interval of one kilometer from x to x + 1 is given by the following expression (in seconds). Here x is a nonnegative integer denoting the distance (in kilometers) from the latest checkpoint where tires are changed (or the start). r,
v, e and f are given constants.
1/(v - e * (x - r)) (if x >= r)
1/(v - f * (r - x)) (if x < r)
Your mission is to write a program to determine the best strategy of tire changes which minimizes the total time to the goal.
Input
The input consists of multiple datasets each corresponding to a race situation. The format of a
dataset is as follows.
n
a1 a2 . . . an
b
r v e f
The meaning of each of the input items is given in the problem statement. If an input line contains two or more input items, they are separated by a space.
n is a positive integer not exceeding 100. Each of a1, a2, ..., and an is a positive integer satisfying 0 < a1 < a2 < . . . < an <= 10000. b is a positive decimal fraction not exceeding 100.0. r is a nonnegative integer satisfying 0 <= r <= an - 1. Each of
v, e and f is a positive decimal fraction. You can assume that v - e * (an - 1 - r) >= 0.01 and v - f * r >= 0.01.
The end of the input is indicated by a line with a single zero.
Output
For each dataset in the input, one line containing a decimal fraction should be output. The decimal fraction should give the elapsed time at the goal (in seconds) when the best strategy is taken. An output line should not contain extra characters such as spaces.
The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.
Sample Input
2 2 3 1.0 1 1.0 0.1 0.3 5 5 10 15 20 25 0.15 1 1.0 0.04 0.5 10 1783 3640 3991 4623 5465 5481 6369 6533 6865 8425 4.172 72 59.4705 0.0052834 0.0611224 0
Sample Output
3.5397 31.9249 168.6682
题意:有n个换轮胎的服务点,一个新的轮胎从x到x+1需要的时间如公式所示,问到终点最短时间是多少。
思路:dp[i]表示在到达第i个站台需要的时间。
AC代码如下:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; double dp[110],cost[10010]; int dis[110],INF=1e9+7; int main() { int n,m,i,j,k,r; double d,b,v,e,f,ret; while(~scanf("%d",&n) && n) { for(i=1;i<=n;i++) scanf("%d",&dis[i]); scanf("%lf%d%lf%lf%lf",&d,&r,&v,&e,&f); for(i=0;i<dis ;i++) { if(i<r) ret=1.0/(v-f*(r-i)); else ret=1.0/(v-e*(i-r)); if(i==0) cost[i]=ret; else cost[i]=cost[i-1]+ret; } for(i=1;i<=n;i++) dp[i]=INF; dp[0]=0; for(i=0;i<n;i++) { if(i==0) ret=0; else ret=d; for(j=i+1;j<=n;j++) dp[j]=min(dp[j],dp[i]+cost[dis[j]-dis[i]-1]+ret); } printf("%.4f\n",dp ); } }
相关文章推荐
- poj1745 0-1DP
- poj 1042 Gone Fishing(DP)
- POJ 1849 Two - dp
- POJ1159 回文数(DP基础题目)+POJ3991(类似题目)
- POJ 1384 Piggy-Bank 背包DP
- POJ - 1463 Strategic game(树形DP)
- POJ-3254 Corn Fields 状态压缩DP+滚动数组
- POJ 1985 Cow Marathon (树形DP,树的直径)
- POJ 1038 状态压缩dp
- poj1655 Balancing Act(树形dp)
- poj 2411 状态压缩dp
- POJ 3071 Football(概率DP)
- poj 2057 树形DP,数学期望
- 【DP】POJ 1252 完全背包
- poj 1038 Bugs Integrated, Inc. __dp状态压缩
- POJ 2533 - Longest Ordered Subsequence(dp 最长递增子序列)
- POJ 1948 Triangular Pastures (用所有的线段组成最大的三角形) DP || 携程员工运动会场地问题
- POJ 1141(Bracket Sequence)-区间DP
- POJ 3254 Corn Fields (状压DP)
- POJ_S1E02_Recursion&DP(1)