fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Point {
  5. double x, y;
  6. };
  7. Point a[100005];
  8. int n;
  9. void init() {
  10. cin >> n;
  11.  
  12. }
  13.  
  14. void solve() {
  15. for (int i = 0; i < n; i++) {
  16. cin >> a[i].x >> a[i].y;
  17. }
  18.  
  19. double tong = 0;
  20. for (int i = 0; i < n - 1; i++) {
  21. double dx = a[i + 1].x - a[i].x;
  22. double dy = a[i + 1].y - a[i].y;
  23. tong += sqrt(dx * dx + dy * dy);
  24. }
  25.  
  26. cout << fixed << setprecision(6) << tong;
  27. }
  28.  
  29. int main() {
  30. init();
  31. solve();
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5292KB
stdin
2
0 0
0 2
stdout
2.000000