GerONSo

4 ЛКШ AC

Apr 20th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #define pragma
  2.  
  3. #ifdef pragma
  4. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
  5. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #endif // pragma
  7.  
  8. #include<bits/stdc++.h>
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11.  
  12. #define ll long long
  13. #define all(x) begin(x), end(x)
  14. #define pb push_back
  15. #define x first
  16. #define y second
  17. #define int long long
  18. #define zero(two) memset(two, 0, sizeof(two))
  19.  
  20. using namespace std;
  21. using namespace __gnu_pbds;
  22.  
  23.  
  24. typedef vector<int> vi;
  25. typedef vector<bool> vb;
  26. typedef pair<int, int> pii;
  27. typedef long double ld;
  28. typedef vector<vi> matrix;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(10);
  39. #if _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 2e3 + 10;
  46. const int INF = 1e18 + 7;
  47. const int MAXLOG = 20;
  48. const int MOD = 998244353;
  49. const int BASE = 47;
  50.  
  51. struct seg {
  52. pii a, b;
  53. };
  54.  
  55. matrix g;
  56. vi pr;
  57. vb used;
  58.  
  59. bool cross(seg a, seg b) {
  60. if(a.a.x != a.b.x) {
  61. swap(a, b);
  62. }
  63. 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) {
  64. 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) {
  65. return 1;
  66. }
  67. }
  68. return 0;
  69. }
  70.  
  71. bool kuhn(int u) {
  72. if(used[u]) return 0;
  73. used[u] = 1;
  74. for(auto v : g[u]) {
  75. if(pr[v] == -1 || kuhn(pr[v])) {
  76. pr[v] = u;
  77. return 1;
  78. }
  79. }
  80. return 0;
  81. }
  82.  
  83. signed main() {
  84. seriy();
  85. int n;
  86. cin >> n;
  87. int cr[n][n];
  88. zero(cr);
  89. vi hor, ver;
  90. vector<seg> segs;
  91. for(int i = 0; i < n; i++) {
  92. int x, y, x1, y1;
  93. cin >> x >> y >> x1 >> y1;
  94. if(x == x1) {
  95. ver.pb(i);
  96. }
  97. else {
  98. hor.pb(i);
  99. }
  100. segs.pb({{x, y}, {x1, y1}});
  101. }
  102. g.resize(n);
  103. for(auto i : ver) {
  104. for(auto j : hor) {
  105. cr[i][j] = cross(segs[i], segs[j]);
  106. cr[j][i] = cross(segs[i], segs[j]);
  107. if(cr[i][j]) {
  108. g[i].pb(j);
  109. g[j].pb(i);
  110. }
  111. }
  112. }
  113. pr.resize(n, -1);
  114. used.resize(n);
  115. for(int i = 0; i < n; i++) {
  116. fill(all(used), 0);
  117. kuhn(i);
  118. }
  119. int cnt = 0;
  120. for(int i = 0; i < n; i++) {
  121. // cerr << pr[i] << " ";
  122. cnt += (pr[i] != -1);
  123. }
  124. cout << cnt / 2 + n - cnt;
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment