先枚举两个矩形,每个矩形横着放或竖着放,把一边拼起来,
如果不是拼起来有缺口就尝试用第三个矩形去补。
如果没有缺口就横着竖着枚举一下第三个矩形和合并的矩形x或y拼接。
#include<bits/stdc++.h> using namespace std; const int N = 300+5; int ax[3][2],ay[3][2]; char g[N][N]; void print_a(int len,int k) { printf("%d\n",len); int ch[] = {'C',k?'B':'A',k?'A':'B'}; for(int i = 0; i < 2; i++){ for(int x = ax[i][0]; x < ax[i][1]; x++){ for(int y = ay[i][0]; y < ay[i][1]; y++){ g[x][y] = ch[i]; } } } for(int i = 0; i < len; i++){ for(int j = 0; j < len; j++){ if(!g[i][j]) putchar(ch[2]); else putchar(g[i][j]); } puts(""); } } //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int x[3],y[3]; for(int i = 0; i < 3; i++) { scanf("%d%d",x+i,y+i); //printf("%d %d\n",x[i],y[i]); } for(int i = 0; i <= 1; i++){ int c = 2,j = i^1; while(c--){ int ct2 = 2; while(ct2--){ int xs = x[i]+x[2]; int del = abs(y[2]-y[i]); if(del){ if(xs != max(y[2],y[i])) { swap(x[i],y[i]); continue;} int cx; if(y[2] > y[i]) cx = x[i]; else cx = x[2]; int ct = 2; while(ct--){ if(y[j] == del && x[j] == cx ){ ax[0][1] = x[2]; ay[0][1] = y[2]; ax[1][0] = x[2]; ax[1][1] = x[2]+x[i]; ay[1][1] = y[i]; print_a(xs,i); return 0; } swap(x[j],y[j]); } }else { int ct = 2; while(ct--){ if(x[j] == xs && y[i]+y[j] == xs){ ax[0][1] = x[2]; ay[0][1] = y[2]; ax[1][0] = x[2]; ax[1][1] = x[2]+x[i]; ay[1][1] = y[i]; print_a(xs,i); return 0; } if(y[j] == y[i] && xs+x[j] == y[i]){ ax[0][1] = x[2]; ay[0][1] = y[2]; ax[1][0] = x[2]; ax[1][1] = x[2]+x[i]; ay[1][1] = y[i]; print_a(y[i],i); return 0; } swap(x[j],y[j]); } } swap(x[i],y[i]); } swap(x[2],y[2]); } } printf("-1\n"); return 0; }