题意:二维平面上有两个框,问平面被分成了几个部分

x,y<=1e9

思路:分类讨论可以

但数据范围实在太小了,离散化以后随便dfs一下

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 typedef long long ll;
  4 typedef unsigned int uint;
  5 typedef unsigned long long ull;
  6 typedef pair<int,int> PII;
  7 typedef pair<ll,ll> Pll;
  8 typedef vector<int> VI;
  9 typedef vector<PII> VII;
 10 #define N  110000
 11 #define M  4100000
 12 #define fi first
 13 #define se second
 14 #define MP make_pair
 15 #define pi acos(-1)
 16 #define mem(a,b) memset(a,b,sizeof(a))
 17 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
 18 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
 19 #define lowbit(x) x&(-x)
 20 #define Rand (rand()*(1<<16)+rand())
 21 #define id(x) ((x)<=B?(x):m-n/(x)+1)
 22 #define ls p<<1
 23 #define rs p<<1|1
 24 
 25 const ll MOD=1e9+7,inv2=(MOD+1)/2;
 26       double eps=1e-6;
 27       int INF=1e9;
 28       int dx[4]={-1,1,0,0};
 29       int dy[4]={0,0,-1,1};
 30 
 31 int read()
 32 {
 33    int v=0,f=1;
 34    char c=getchar();
 35    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
 36    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
 37    return v*f;
 38 }
 39 
 40 struct arr
 41 {
 42     int x,id;
 43 }x[10],y[10];
 44 int b[20][20],c[20],d[20];
 45 
 46 bool cmp(arr a,arr b)
 47 {
 48     return a.x<b.x;
 49 }
 50 
 51 void dfs(int x,int y)
 52 {
 53     //printf("x=%d y=%d\n",x,y);
 54     b[x][y]=1;
 55     rep(i,0,3)
 56     {
 57         int ux=x+dx[i],uy=y+dy[i];
 58         if(ux>0&&ux<15&&uy>0&&uy<15&&b[ux][uy]==0) dfs(ux,uy);
 59     }
 60 }
 61 
 62 int main()
 63 {
 64     //freopen("1.in","r",stdin);
 65     int cas;
 66     scanf("%d",&cas);
 67     while(cas--)
 68     {
 69         x[1].x=read(),y[1].x=read(),x[2].x=read(),y[2].x=read();
 70         x[3].x=read(),y[3].x=read(),x[4].x=read(),y[4].x=read();
 71         rep(i,1,4)
 72         {
 73             x[i].id=y[i].id=i;
 74         }
 75         sort(x+1,x+4+1,cmp);
 76         sort(y+1,y+4+1,cmp);
 77         int m1=2,m2=2;
 78         c[x[1].id]=2;
 79         d[y[1].id]=2;
 80         rep(i,2,4)
 81         {
 82             if(x[i].x==x[i-1].x) c[x[i].id]=m1;
 83              else
 84              {
 85                  m1+=2;
 86                  c[x[i].id]=++m1;
 87              }
 88             if(y[i].x==y[i-1].x) d[y[i].id]=m2;
 89              else
 90              {
 91                  m2+=2;
 92                  d[y[i].id]=++m2;
 93              }
 94         }
 95         rep(i,1,15)
 96          rep(j,1,15) b[i][j]=0;
 97         rep(i,d[1],d[2]) b[c[1]][i]=b[c[2]][i]=1;
 98         rep(i,d[3],d[4]) b[c[3]][i]=b[c[4]][i]=1;
 99         rep(i,c[1],c[2]) b[i][d[2]]=b[i][d[1]]=1;
100         rep(i,c[3],c[4]) b[i][d[4]]=b[i][d[3]]=1;
101         int ans=0;
102         rep(i,1,14)
103          rep(j,1,14)
104           if(b[i][j]==0)
105           {
106               ans++;
107               dfs(i,j);
108           }
109 
110         printf("%d\n",ans);
111 
112 
113     }
114 
115     return 0;
116 }