Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <math.h>
- #include <vector>
- #include <cstdio>
- using namespace std;
- vector<double> up;
- vector<double> down;
- int main() {
- //freopen("sweets.in", "r", stdin);
- //freopen("sweets.out", "w", stdout);
- int n, m;
- cin >> n >> m;
- int a, b, apr;
- double k, b1, y1, y2, x1, x2;
- cin >> a >> b;
- apr = a;
- up.push_back(b);
- for (int i = 1; i< n; i++)
- {
- cin >> a >> b;
- if (apr + 1 == a)
- up.push_back(b);
- else
- {
- y2 = b;
- y1 = up[up.size() - 1];
- x1 = apr;
- x2 = a;
- k = (y1 - y2) / (x1 - x2);
- b1 = y1 - (x1 * k);
- for (int j = apr + 1; j <= a; j++)
- {
- up.push_back(k * j + b1);
- }
- }
- apr = a;
- }
- cin >> a >> b;
- apr = a;
- down.push_back(b);
- for (int i = 1; i < m; i++)
- {
- cin >> a >> b;
- if (apr + 1 == a)
- down.push_back(b);
- else
- {
- y2 = b;
- y1 = down[down.size() - 1];
- x1 = apr;
- x2 = a;
- k = (y1 - y2) / (x1 - x2);
- b1 = y1 - (x1 * k);
- for (int j = apr + 1; j <= a; j++)
- {
- down.push_back(k * j + b1);
- }
- }
- apr = a;
- }
- double minr = 1000000000;
- for (int i = 0; i < up.size(); i++)
- {
- if (up[i] - down[i] < minr)
- minr = up[i] - down[i];
- }
- int ans = 0;
- bool flag = false;
- for (int i = 0; i < up.size(); i++)
- {
- if ((abs(up[i] - down[i] - minr) <= 0.0001) && flag)
- {
- flag = false;
- }
- else if ((!flag) && (abs(up[i] - down[i] - minr) >= 0.0001))
- {
- flag = true;
- ans++;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement