记录编号 382913 评测结果 AAAAAAAAAA
题目名称 岛国 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.215 s
提交时间 2017-03-14 20:34:45 内存使用 0.42 MiB
显示代码纯文本
  1. /*kZime*/
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <algorithm>
  9. #define MAXN
  10.  
  11. using namespace std;
  12.  
  13. int n, u[5333], ans;
  14.  
  15. inline int read() {
  16. int k = 0, f = 1; char c = getchar();
  17. for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
  18. for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  19. return k * f;
  20. }
  21.  
  22. struct land{
  23. int x1, y1, x2, y2;
  24. void in() {
  25. x1 = read();
  26. y1 = read();
  27. x2 = read();
  28. y2 = read();
  29. }
  30. }l[5333];
  31.  
  32. int getf(int x) {
  33. if(u[x] != x) u[x] = getf(u[x]);
  34. return u[x];
  35. }
  36.  
  37. bool Union(int a, int b) {
  38. int fa = getf(a), fb = getf(b);
  39. if(fa == fb) {
  40. return false;
  41. }
  42. u[fb] = fa;
  43. return true;
  44. }
  45.  
  46. bool p_(land a, land b) {
  47. if(a.x2 < b.x1 - 1 || a.y2 < b.y1 - 1 || a.y1 - 1 > b.y2) return false;
  48. if(a.x2 == b.x1 - 1) {
  49. if(a.y2 < b.y1) return false;
  50. if(a.y1 > b.y2) return false;
  51. }
  52. return true;
  53. }
  54.  
  55. bool cmp(const land &a, const land &b) {
  56. return a.x1 < b.x1;
  57. }
  58.  
  59.  
  60. int main() {
  61. #ifndef LOCAL
  62. freopen("jx.in", "r", stdin);
  63. freopen("jx.out", "w", stdout);
  64. #else
  65. freopen("in.txt", "r", stdin);
  66. #endif
  67. n = read();
  68. ans = n;
  69. for(int i = 1; i <= n; i++) {
  70. u[i] = i;
  71. l[i].in();
  72. }
  73. sort(l + 1, l + n + 1, cmp);
  74. // for(int i = 1; i <= n; i++) {
  75. // printf("%d %d %d %d\n",l[i].x1, l[i].x2, l[i].y1, l[i].y2);
  76. // }
  77. for(int i = 1; i <= n; i++) {
  78. for(int j = i + 1; j <= n; j++) {
  79. if(p_(l[i], l[j]) && Union(i, j)) {
  80. ans--;
  81. if(ans == 1){
  82. printf("1");
  83. return 0;
  84. }
  85. }
  86. }
  87. }
  88. printf("%d",ans);
  89. return 0;
  90. }
  91.  
  92.