Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct vect
- {
- long long x, y;
- vect(long long x, long long y) : x(x), y(y) {}
- long long operator *(vect a)
- {
- if (x * a.y - y * a.x == 0) return 0;
- return (x * a.y - y * a.x) / abs(x * a.y - y * a.x);
- }
- vect operator -(vect a)
- {
- return vect(x - a.x, y - a.y);
- }
- };
- struct seg
- {
- long long x1, y1, x2, y2;
- seg(long long x1, long long y1, long long x2, long long y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
- };
- bool intersect(seg ab, seg cd)
- {
- vect a1 = vect(ab.x2, ab.y2) - vect(ab.x1, ab.y1);
- vect ac = vect(cd.x1, cd.y1) - vect(ab.x1, ab.y1);
- vect ad = vect(cd.x2, cd.y2) - vect(ab.x1, ab.y1);
- vect c1 = vect(cd.x2, cd.y2) - vect(cd.x1, cd.y1);
- vect ca = vect(ab.x1, ab.y1) - vect(cd.x1, cd.y1);
- vect cb = vect(ab.x2, ab.y2) - vect(cd.x1, cd.y1);
- return (c1 * ca) * (c1 * cb) <= 0 && (a1 * ac) * (a1 * ad) <= 0;
- }
- vector<int> a[250];
- vector<int> mt;
- vector<char> used;
- bool try_kuhn (int v) {
- if (used[v]) return false;
- used[v] = true;
- for (size_t i=0; i<a[v].size(); ++i) {
- int to = a[v][i];
- if (mt[to] == -1 || try_kuhn (mt[to])) {
- mt[to] = v;
- return true;
- }
- }
- return false;
- }
- int main()
- {
- int n;
- cin >> n;
- vector<seg> v;
- for (int i = 0; i < n; i++)
- {
- long long x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- v.push_back(seg(x1, y1, x2, y2));
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (j == i) continue;
- if (intersect(v[i], v[j]))
- {
- a[i].push_back(j);
- }
- }
- }
- mt.assign (n, -1);
- for (int i = 0; i < n; ++i) {
- if (v[i].x1 == v[i].x2)
- {
- used.assign (n, false);
- try_kuhn (i);
- }
- }
- int ans = 0;
- for (int i=0; i<n; ++i)
- if (mt[i] != -1)
- ans++;
- cout << n - ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement