题意
给出两个矩形,问这两个矩形把平面分成了几部分。
分析
不需要什么高级技能,只需 “简单” 的分类讨论。
(实在太难写了,对拍找出错误都不想改
推荐 博客,其中有个很好的思路,即只讨论答案为2,3,5,6的情况,其余都为4,这样可以省掉一些麻烦。
#include <bits/stdc++.h> using namespace std; int main() { int x11, x12, y11, y12; int x21, x22, y21, y22; int x1, y1, x2, y2; int T; scanf("%d", &T); while(T--) { scanf("%d %d %d %d %d %d %d %d", &x11, &y11, &x12, &y12, &x21, &y21, &x22, &y22); if(x11 == x21 && x12 == x22 && y11 == y21 && y12 == y22) { printf("2 "); continue; } if(x12 <= x21 || x22 <= x11 || y12 <= y21 || y22 <= y11) { printf("3 "); continue; } if((x11 > x21 && x12 < x22 && y11 > y21 && y12 < y22) || (x11 < x21 && x12 > x22 && y11 < y21 && y12 > y22)) { printf("3 "); continue; } // if((x11 == x21 && y11 >= y21 && x12 < x22 && y12 <= y22) || (x11 == x21 && y11 <= y21 && x12 > x22 && y12 >= y22)) { printf("3 "); continue; } if((x11 > x21 && y11 >= y21 && x12 == x22 && y12 <= y22) || (x11 < x21 && y11 <= y21 && x12 == x22 && y12 >= y22)) { printf("3 "); continue; } if((x11 >= x21 && y11 == y21 && x12 <= x22 && y12 < y22) || (x11 <= x21 && y11 == y21 && x12 >= x22 && y12 > y22)) { printf("3 "); continue; } if((x11 >= x21 && y11 > y21 && x12 <= x22 && y12 == y22) || (x11 <= x21 && y11 < y21 && x12 >= x22 && y12 == y22)) { printf("3 "); continue; } if((x11 > x21 && y11 < y21 && x12 < x22 && y12 > y22) || (x11 < x21 && y11 > y21 && x12 > x22 && y12 < y22)) { printf("6 "); continue; } if((x12 < x22 && y12 == y22 && x11 > x21 && y11 < y21) || (x12 > x22 && y12 == y22 && x11 < x21 && y11 > y21)) { printf("5 "); continue; } if((x12 < x22 && y12 > y22 && x11 > x21 && y11 == y21) || (x12 > x22 && y12 < y22 && x11 < x21 && y11 == y21)) { printf("5 "); continue; } if((x12 == x22 && y12 < y22 && x11 < x21 && y11 > y21) || (x12 == x22 && y12 > y22 && x11 > x21 && y11 < y21)) { printf("5 "); continue; } if((x12 > x22 && y12 < y22 && x11 == x21 && y11 > y21) || (x12 < x22 && y12 > y22 && x11 == x21 && y11 < y21)) { printf("5 "); continue; } printf("4 "); } return 0; }