[关闭]
@PaulGuan 2016-10-02T10:27:51.000000Z 字数 502 阅读 683

E - Wasted Time 题解

Algorithm


题目大意

每次需要在n (2<=n<=100) 个点之间依次连线,每个单位长度的耗时为0.02个单位时间,连线会有重复,计算k (1<=k<=1000) 次连线所消耗的时间,结果保留9位小数。

分析

每次计算两个点之间的距离,然后相加,最后*0.02*k即可。

代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. using namespace std;
  6. double len(double x1,double y1,double x2,double y2)
  7. {
  8. return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  9. }
  10. int main(void)
  11. {
  12. int n,k;
  13. double ans=0;
  14. cin>>n>>k;
  15. int i;
  16. double a,b,c,d;
  17. cin>>a>>b;
  18. for(i=1;i<n;i++)
  19. {
  20. cin>>c>>d;
  21. ans+=len(a,b,c,d)*0.02;
  22. swap(a,c);
  23. swap(b,d);
  24. }
  25. printf("%.9lf\n",ans*k);
  26. return 0;
  27. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注