Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #endif // pragma
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define pb push_back
- #define x first
- #define y second
- #define int long long
- #define zero(two) memset(two, 0, sizeof(two))
- using namespace std;
- using namespace __gnu_pbds;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(10);
- #if _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int MAXN = 2e3 + 10;
- const int INF = 1e18 + 7;
- const int MAXLOG = 20;
- const int MOD = 998244353;
- const int BASE = 47;
- struct seg {
- pii a, b;
- };
- matrix g;
- vi pr;
- vb used;
- bool cross(seg a, seg b) {
- if(a.a.x != a.b.x) {
- swap(a, b);
- }
- if(a.a.y <= b.a.y && a.b.y >= b.a.y || a.b.y <= b.a.y && a.a.y >= b.a.y) {
- if(a.a.x >= b.a.x && a.a.x <= b.b.x || a.a.x >= b.b.x && a.a.x <= b.a.x) {
- return 1;
- }
- }
- return 0;
- }
- bool kuhn(int u) {
- if(used[u]) return 0;
- used[u] = 1;
- for(auto v : g[u]) {
- if(pr[v] == -1 || kuhn(pr[v])) {
- pr[v] = u;
- return 1;
- }
- }
- return 0;
- }
- signed main() {
- seriy();
- int n;
- cin >> n;
- int cr[n][n];
- zero(cr);
- vi hor, ver;
- vector<seg> segs;
- for(int i = 0; i < n; i++) {
- int x, y, x1, y1;
- cin >> x >> y >> x1 >> y1;
- if(x == x1) {
- ver.pb(i);
- }
- else {
- hor.pb(i);
- }
- segs.pb({{x, y}, {x1, y1}});
- }
- g.resize(n);
- for(auto i : ver) {
- for(auto j : hor) {
- cr[i][j] = cross(segs[i], segs[j]);
- cr[j][i] = cross(segs[i], segs[j]);
- if(cr[i][j]) {
- g[i].pb(j);
- g[j].pb(i);
- }
- }
- }
- pr.resize(n, -1);
- used.resize(n);
- for(int i = 0; i < n; i++) {
- fill(all(used), 0);
- kuhn(i);
- }
- int cnt = 0;
- for(int i = 0; i < n; i++) {
- // cerr << pr[i] << " ";
- cnt += (pr[i] != -1);
- }
- cout << cnt / 2 + n - cnt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment