24h購物| | PChome| 登入
2013-09-22 21:27:09| 人氣862| 回應0 | 上一篇 | 下一篇

[UVA][dp] 1250 - Robot Challenge

推薦 0 收藏 0 轉貼0 訂閱站台

You have entered a robot in a Robot Challenge. A course is set up in a 100m by 100m space. Certain points are identified within the space as targets. They are ordered -- there is a target 1, a target 2, etc. Your robot must start at (0,0). From there, it should go to target 1, stop for 1 second, go to target 2, stop for 1 second, and so on. It must finally end up at, and stop for a second on, (100,100).

Each target except (0,0) and (100,100) has a time penalty for missing it. So, if your robot went straight from target 1 to target 3, skipping target 2, it would incur target 2's penalty. Note that once it hits target 3, it cannot go back to target 2. It must hit the targets in order. Since your robot must stop for 1 second on each target point, it is not in danger of hitting a target accidentally too soon. For example, if target point 3 lies directly between target points 1 and 2, your robot can go straight from 1 to 2, right over 3, without stopping. Since it didn't stop, the judges will not mistakenly think that it hit target 3 too soon, so they won't assess target 2's penalty. Your final score is the amount of time (in seconds) your robot takes to reach (100,100), completing the course, plus all penalties. Smaller scores are better.

Your robot is very maneuverable, but a bit slow. It moves at 1 m/s, but can turn very quickly. During the 1 second it stops on a target point, it can easily turn to face the next target point. Thus, it can always move in a straight line between target points.

Because your robot is a bit slow, it might be advantageous to skip some targets, and incur their penalty, rather than actually maneuvering to them. Given a description of a course, determine your robot's best (lowest) possible score.

Input 

There will be several test cases. Each test case will begin with a line with one integer, N (1$ le$N$ le$1000) which is the number of targets on the course. Each of the next N lines will describe a target with three integers, X, Y and P, where (X, Y) is a location on the course ( 1$ le$X, Y$ le$99, X and Y in meters) and P is the penalty incurred if the robot misses that target (1$ le$P$ le$100). The targets will be given in order -- the first line after N is target 1, the next is target 2, and so on. All the targets on a given course will be unique -- there will be at most one target point at any location on the course. End of input will be marked by a line with a single `0'.

Output 

For each test case, output a single decimal number, indicating the smallest possible score for that course. Output this number rounded (NOT truncated) to three decimal places. Print each answer on its own line, and do not print any blank lines between answers.

Sample Input 

1 
50 50 20 
3 
30 30 90 
60 60 80 
10 90 100 
3 
30 30 90 
60 60 80 
10 90 10 
0

Sample Output 

143.421 
237.716 
154.421



題目描述:

機器人的比賽吧?這是馬術競賽嗎?

目標有 n 個,必須按照順序跳,過頭就不能回去跳了。

每抵達一個目標時,會消耗 1 單位的罰分通過目標,如果忽略一個目標時,會得到該目標的罰分。

比賽過程中,時間消耗也是罰分,機器人的速度 1,而且轉方向幾乎是瞬間。

跑的時候按照歐幾里得距離計算。

求最少罰分。

題目解法:


動態規劃,dp[i] 表示當前停留的目標編號。

#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
double dp[1005];
int X[1005], Y[1005], P[1005];
int main() {
int i, j, k, n;
while(scanf("%d", &n) == 1 && n) {
for(i = 1; i <= n; i++)
scanf("%d %d %d", &X[i], &Y[i], &P[i]);
X[0] = Y[0] = P[0] = 0;
X[n+1] = Y[n+1] = 100, P[n+1] = 0;
for(i = 0; i <= n+1; i++)
dp[i] = 1e+30;
dp[0] = 0;
for(i = 0; i <= n; i++) {
int p = 0;
for(j = i+1; j <= n+1; j++) {
dp[j] = min(dp[j], dp[i]+p+hypot(X[i]-X[j], Y[i]-Y[j])+1);
p += P[j];
}
}
printf("%.3lf\n", dp[n+1]);
}
return 0;
}
 

台長: Morris
人氣(862) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][maxflow] 12159 - Gun Fight
此分類上一篇:[UVA][窮舉&二分&貪婪] 1079 - A Careful Approach

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文