Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- //#pragma GCC optimize("O3")
- //#pragma GCC optimize("unroll-loops")
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define x first
- #define y second
- #define sz(x) (int)x.size()
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pi;
- typedef pair<ld, ld> pld;
- typedef pair<ll, ll> pl;
- typedef vector<int> veci;
- typedef vector<bool> vecb;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<bool>> vvb;
- const int INF_I = 1e9;
- const ll INF_LL = 1e18;
- const int MOD = 1000000007;
- const double eps = 1e-6;
- pld m(pld a, pld b){
- return {b.x - a.x, b.y - a.y};
- }
- ld vec(pld a, pld b){
- return a.x * b.y - a.y * b.x;
- }
- ld l(pld a, pld b){
- return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- vector<pi> a(n);
- pi mn = {INF_I, INF_I};
- for (int i = 0; i < n; i++) {
- cin >> a[i].x >> a[i].y;
- mn = min(mn, a[i]);
- }
- for (int i = 0; i < n; i++) {
- a[i] = {a[i].x - mn.x, a[i].y - mn.y};
- }
- a.erase(find(all(a), mp(0, 0)));
- sort(all(a), [](pi a1, pi a2){
- return atan2(a1.y, a1.x) < atan2(a2.y, a2.x);
- });
- a.eb(mp(0, 0));
- for (int i = n-1; i >= 1; i--)
- swap(a[i], a[i-1]);
- veci b;
- b.reserve(n);
- b.eb(0), b.eb(1);
- for (int i = 2; i < n; i++){
- pld v1 = m(a[b[sz(b)-2]], a[i]);
- pld v2 = m(a[b[sz(b)-2]], a[b[sz(b)-1]]);
- while (sz(b) >= 2 && vec(v2, v1) < 0) {
- b.pop_back();
- v1 = m(a[b[sz(b)-2]], a[i]);
- v2 = m(a[b[sz(b)-2]], a[b[sz(b)-1]]);
- }
- b.eb(i);
- }
- ld P = 0;
- ld S = 0;
- for (int i = 0; i < sz(b); i++) {
- S += vec(a[b[i]], a[b[(i + 1) % sz(b)]]) * 0.5;
- P += l(a[b[i]], a[b[(i + 1) % sz(b)]]);
- }
- cout << fixed << P << " " << fabs(S) << "\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment