在最外围的一圈没有意义,所以全都涂黑,内部贪心地涂成棋盘即可。
#include<cstdio> #include<cstring> using namespace std; int n,m,K,T; bool a[30][30]; int main(){ freopen("figure.in","r",stdin); freopen("figure.out","w",stdout); scanf("%d",&T); for(int zu=1;zu<=T;++zu){ memset(a,0,sizeof(a)); scanf("%d%d%d",&n,&m,&K); if(K>((n-2)*(m-2)+1)/2 || n<=2 || m<=2){ puts("Impossible"); } else{ int pen,cnt=0; for(int i=2;i<n;++i){ pen=i; for(int j=2;j<m;++j){ ++pen; if(pen&1){ ++cnt; a[i][j]=1; if(cnt==K){ goto OUT; } } } } OUT: for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ if(a[i][j]){ putchar('#'); } else{ putchar('.'); } } puts(""); } } if(zu!=T){ puts(""); } } return 0; }