Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------- Code written by Kabeton --------------------*/
- /*--- Contacts: https://vk.com/kabeton and TheKabeton@yandex.ru ---*/
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <unordered_map>
- #include <set>
- #include <bitset>
- #include <tuple>
- #include <queue>
- #include <stack>
- #include <valarray>
- #include <sstream>
- #include <cstring>
- #include <numeric>
- #include <ctime>
- #include <cassert>
- using namespace std;
- #define endl "\n"
- #define re return
- #define fi first
- #define se second
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef pair<ll, ll> pll;
- typedef vector<ll> vll;
- typedef vector<vll> vvll;
- typedef vector<pll> vpll;
- typedef vector<vpll> vvpll;
- const ll mod = 1e9 + 7;
- const ll inf = 1e15;
- struct pt {
- double x, y;
- };
- struct line {
- double a, b, c;
- };
- const double EPS = 1e-9;
- double det (double a, double b, double c, double d) {
- return a * d - b * c;
- }
- bool intersect (line m, line n, pt & res) {
- double zn = det (m.a, m.b, n.a, n.b);
- if (abs (zn) < EPS)
- return false;
- res.x = - det (m.c, m.b, n.c, n.b) / zn;
- res.y = - det (m.a, m.c, n.a, n.c) / zn;
- return true;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- ll n, h, x, y, xh, yh;
- long double ans = 0;
- cin >> n >> h;
- vector<pair<ll, ll>> v;
- for (ll i = 0; i < n; ++i) {
- cin >> x >> y;
- v.emplace_back(x, y);
- }
- xh = v[0].first;
- yh = v[0].second + h;
- long double alpha = M_PI + M_PI / 2;
- ll xm = -1;
- ll ym = -1;
- ll q = 0;
- for (ll i = 0; i < n; ++i) {
- long double alpha2;
- ll xc = xh -= v[i].first;
- ll yc = yh -= v[i].second;
- if (xc == 0) {
- if (y > 0) {
- alpha2 = M_PI / 2;
- } else {
- alpha2 = M_PI + M_PI / 2;
- }
- } else {
- alpha2 = atan(yc / xc);
- }
- if ((alpha2 - alpha + 0.0000000001) > 0) {
- if (q == 1) {
- q = 0;
- pt ptt{0, 0};
- double a, b, c;
- a = yh - ym;
- b = xm - xh;
- c = -a * xh - b * yh;
- line line1{a, b, c};
- a = v[i].second - v[i - 1].second;
- b = v[i - 1].first - v[i].first;
- c = -a * v[i].first - b * v[i].second;
- line line2{a, b, c};
- intersect(line1, line2, ptt);
- ans += sqrt((v[i].first - ptt.x) * (v[i].first - ptt.x) +
- (v[i].second - ptt.y) * (v[i].second - ptt.y));
- } else {
- alpha = alpha2;
- xm = v[i].first;
- ym = v[i].second;
- }
- } else {
- ans += sqrt((v[i].first - v[i - 1].first) * (v[i].first - v[i - 1].first) +
- (v[i].second - v[i - 1].second) * (v[i].second - v[i - 1].second));
- q = 1;
- }
- }
- cout << ans;
- re 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement