matheus_monteiro

Trying to Impress Cleopatra

Dec 26th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define ii pair<int, int>
  6. #define fi first
  7. #define se second
  8. #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  9.  
  10. int sq(int x) {
  11.     return x * x;
  12. }
  13.  
  14. double dist(ii a, ii b) {
  15.     return sqrt((double)(sq(a.fi - b.fi) + sq(a.se - b.se)));
  16. }
  17.  
  18. ii operator-(ii a, ii b) {
  19.     return ii(a.fi - b.fi, a.se - b.se);
  20. }
  21.  
  22. int operator*(ii a, ii b) {
  23.     return a.fi * b.fi + a.se * b.se;
  24. }
  25.  
  26. void solve(){
  27.     vector<ii> arr;
  28.     int n;
  29.  
  30.     cin >> n;
  31.     for(int i = 0; i < n; ++i) {
  32.         int x, y;
  33.         cin >> x >> y;
  34.         arr.push_back({x, y});
  35.     }
  36.     for(int i = 0; i < n; ++i)
  37.         arr.push_back(arr[i]);
  38.    
  39.     double sum = 0;
  40.    
  41.     for(int i = 0, j = 0; i < n; ++i) {
  42.         while((j - i + 1) <= n and (arr[i + 1] - arr[i]) * (arr[j + 1] - arr[j]) > 0) {
  43.             sum += dist(arr[j + 1], arr[j]);
  44.             ++j;
  45.         }
  46.         cout << fixed << setprecision(20) << sum << '\n';
  47.         sum -= dist(arr[i + 1], arr[i]);
  48.     }
  49. }
  50.  
  51. int32_t main() {
  52.     fastio;
  53.     solve();
  54.     return 0;
  55. }
Add Comment
Please, Sign In to add comment