A - Wasted Time CodeForces - 127A——sqrt()+pow()

冷不防 2022-06-14 02:12 214阅读 0赞

Think:
1>题意建模:一个平面按照输入顺序连接n个点,已知连接速度,共k个平面,求所需时间
2>知识点建议:sqrt()+pow(()

  1. A - Wasted Time CodeForces - 127A
  2. Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
  3. Mr. Scrooge's signature can be represented as a polyline A1A2... An. Scrooge signs like that: first it places a pen at the point A1, then draws a segment from point A1 to point A2, then he draws a segment from point A2 to point A3 and so on to point An, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
  4. Scrooge signed exactly k papers throughout his life and all those signatures look the same.
  5. Find the total time Scrooge wasted signing the papers.

Input

  1. The first line contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ 1000). Each of the following n lines contains the coordinates of the polyline's endpoints. The i-th one contains coordinates of the point Ai — integers xi and yi, separated by a space.
  2. All points Ai are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.

Output

  1. Print one real number the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10 - 6.

Example
Input

  1. 2 1
  2. 0 0
  3. 10 0
  4. Output
  5. 0.200000000
  6. Input
  7. 5 10
  8. 3 1
  9. -5 6
  10. -2 -1
  11. 3 2
  12. 10 0
  13. Output
  14. 6.032163204
  15. Input
  16. 6 10
  17. 5 0
  18. 4 0
  19. 6 0
  20. 3 0
  21. 7 0
  22. 2 0
  23. Output
  24. 3.000000000

以下为Accepted代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, k, i, a[4];
  5. while(scanf("%d %d", &n, &k) != EOF){
  6. double sum = 0;
  7. scanf("%d %d", &a[0], &a[1]);
  8. for(i = 1; i < n; i++){
  9. scanf("%d %d", &a[2], &a[3]);
  10. sum += sqrt(pow(a[2]-a[0], 2)+pow(a[3]-a[1], 2));
  11. for(int j = 0; j < 2; j++)
  12. a[j] = a[j+2];
  13. }
  14. printf("%.9lf\n", sum*(double)k/50.0);
  15. }
  16. return 0;
  17. }

发表评论

表情:
评论列表 (有 0 条评论,214人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CodeForces679A

    [CodeForces679A][] 也是交互题,这个要稍微难一些. 考虑的过程大概是: \\(1\\)肯定没有问的价值,如果问过\\(2\\),那么除了\\(4\

    相关 CodeForces1214A

    [CodeForces1214A][] 说起来你们可能不信,这题硬生生卡了我\\(1h\\),我想了背包,扩欧,二分....等等一坨办法.结果最后还是用了\\(bfs\\)

    相关 codeforce 141A

    /字符串问题 没AC的人可能是没看清楚题目吧, 先大概说下题目大意: 给你3个字符串,如果第一个串和第二个串组合在一起可以等于第三个串就输出“Y