链接
[http://codeforces.com/contest/989/problem/C]
题意
给定A B C D四个字符个数,让你构造一个矩阵使得他们的个数恰好那么多,联通块算一块
分析
构造50*50的矩阵,分成4个区域让不同的插进其他的领域,对角插入,不然有联通块。
代码
#include<bits/stdc++.h>
using namespace std;
char ans[52][52];
void color(int x,int y,char ch){
for(int i=1;i<=25;i++)
for(int j=1;j<=25;j++)
ans[i+x][j+y]=ch;
}
void solve(int x,int y,char ch,int n){
for(int i=1;i<=25&&n;i+=2)
for(int j=1;j<=25&&n;j+=2)
{
ans[x+i][y+j]=ch;
n--;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int a,b,c,d;
//freopen("in.txt","r",stdin);
cin>>a>>b>>c>>d;
color(0, 0, 'C');
color(0, 25, 'D');
color(25, 25, 'A');
color(25, 0, 'B');
solve(0, 0, 'A', a-1);
solve(0, 25, 'B', b-1);
solve(25, 25, 'C', c-1);
solve(25, 0, 'D', d-1);
puts("50 50");
for(int i=1;i<=50;i++)
{
for(int j=1;j<=50;j++)
putchar(ans[i][j]);
putchar('\n');
}
return 0;
}