Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define ii pair<int, int>
- #define fi first
- #define se second
- #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- int sq(int x) {
- return x * x;
- }
- double dist(ii a, ii b) {
- return sqrt((double)(sq(a.fi - b.fi) + sq(a.se - b.se)));
- }
- ii operator-(ii a, ii b) {
- return ii(a.fi - b.fi, a.se - b.se);
- }
- int operator*(ii a, ii b) {
- return a.fi * b.fi + a.se * b.se;
- }
- void solve(){
- vector<ii> arr;
- int n;
- cin >> n;
- for(int i = 0; i < n; ++i) {
- int x, y;
- cin >> x >> y;
- arr.push_back({x, y});
- }
- for(int i = 0; i < n; ++i)
- arr.push_back(arr[i]);
- double sum = 0;
- for(int i = 0, j = 0; i < n; ++i) {
- while((j - i + 1) <= n and (arr[i + 1] - arr[i]) * (arr[j + 1] - arr[j]) > 0) {
- sum += dist(arr[j + 1], arr[j]);
- ++j;
- }
- cout << fixed << setprecision(20) << sum << '\n';
- sum -= dist(arr[i + 1], arr[i]);
- }
- }
- int32_t main() {
- fastio;
- solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment