Meaning of the questions:
Given two rectangles, the outputs of the two rectangular plane is divided into many pieces.
answer:
Road could have been great debate geometric computing, and by my life and written bfs.
Discrete edge edges do not coincide with the middle note to empty out a grid, surrounded by a circle also vacant, then violence bfs calculate a total of a few can.
The method is not so it would not be no violence, under observation chart, point and rectangle there is 25 kinds of relationship, then two points define a rectangular, two rectangular relationship between the total of 625 kinds
As for the table how to play, as if it had to help bfs.
#include<iostream> #include<queue> #include<algorithm> #include<cstring> using namespace std; int mapp[11][11]; int x[5],y[5]; const int changex[4]={0,0,1,-1}; const int changey[4]={1,-1,0,0}; void lsh(int *a){ int b[5]; bool flag[5]={}; b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4]; sort(b+1,b+5); int l=unique(b+1,b+5)-b-1; for(int i=1;i<=l;i++){ for(int j=1;j<=4;j++){ if(a[j]==b[i] && flag[j]==0){ a[j]=2*i; flag[j]=1; } } } return ; } int solve(){ int ans=0; memset(mapp,0,sizeof mapp); // printf("a:%d %d %d %d\n",x[1],y[1],x[2],y[2]); // printf("b:%d %d %d %d\n",x[3],y[3],x[4],y[4]); for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ if((i==x[1] || i==x[2]) && j>=y[1] && j<=y[2]){ mapp[i][j]=-1; } if((j==y[1] || j==y[2]) && i>=x[1] && i<=x[2]){ mapp[i][j]=-1; } if((i==x[3] || i==x[4]) && j>=y[3] && j<=y[4]){ mapp[i][j]=-1; } if((j==y[3] || j==y[4]) && i>=x[3] && i<=x[4]){ mapp[i][j]=-1; } } } // for(int i=1;i<=10;i++){ // for(int j=1;j<=10;j++){ // printf("%c ",mapp[i][j]==-1?'*':Folder [i] [j] + '0'); // } // printf("\n"); // } // queue<int> qx,qy; for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ if(mapp[i][j]==0){ ans++; mapp[i][j]=ans; qx.push(i); qy.push(j); } while(!qx.empty()){ int xx=qx.front(); int yy=qy.front(); qx.pop();qy.pop(); // printf("%d %d:",xx,yy); for(int k=0;k<4;k++){ int xxx=xx+changex[k]; int yyy=yy+changey[k]; // printf("%d %d ",xxx,yyy); if(xxx>=1 && xxx<=10 && yyy>=1 && yyy<=10 && mapp[xxx][yyy]==0){ qx.push(xxx); qy.push(yyy); mapp[xxx][yyy]=ans; } } // printf("\n"); } // for(int i=1;i<=10;i++){ // for(int j=1;j<=10;j++){ // printf("%c ",mapp[i][j]==-1?'*':mapp[i][j]+'0'); // } // printf("\n"); // } } } return ans; } int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d %d %d %d",&x[1],&y[1],&x[2],&y[2]); scanf("%d %d %d %d",&x[3],&y[3],&x[4],&y[4]); lsh(x);lsh(y); printf("%d\n",solve()); // for(int i=1;i<=10;i++){ // for(int j=1;j<=10;j++){ // printf("%c ",mapp[i][j]==-1?'*':mapp[i][j]+'0'); // } // printf("\n"); // } } }