编程介的小学生 2017-11-26 14:24 采纳率: 20.5%
浏览 810
已采纳

A Rod in a Path

Problem Description
Alice has a rod. One day, she draws a path on a grid and puts the rod on it. The path begins at (0, 0) and continues to the right. The first and last segments are always horizontal, so there are always an odd number of segments. If we number the segments 1, 2, … , n, odd-numbered segments are all horizontal, while other segments (if any) are vertical. Initially, one endpoint B of the rod is located at (0, 0), and the other endpoint A is at (L, 0), where L is the length of the rod. The length of the first segment is at least L. When moving the rod, both endpoints A and B must be always on the path, though other parts may be outside. The rod is hard, so its length (i.e. distance between A and B) is always L.

Write a program to compute the minimum distance A must cover to reach the rightmost endpoint of the path.

Input
The input consists of several test cases. The first line of each case contains two integers n and L (1 ≤ n ≤ 10, 1 ≤ L ≤ 30),described above. The second line contains n non-zero integers li (-30 ≤ li ≤ 30), the lengths and directions of path segments. The absolute value of li denotes length of the i-th segment. If it is horizontal, li is positive. That means, horizontal segments are always left-to-right. If it is vertical, positive means down-to-up (increasing y coordinate), negative means up-to-down (decreasing y coordinate). The last test case is followed by a single zero, which should not be processed.

Output
For each test case, print the case number and the minimum distance to two decimal places. If it's not possible to reach the rightmost point, print -1.

Sample Input
3 5
8 6 2
5 2
3 1 1 -4 1
0

Sample Output
Case 1: 11.00
Case 2: 10.00

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-01-26 13:58
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line