Codeforces Round #487 (Div. 2) C. A Mist of Florescence 构造
题意:
让你构造一个 矩阵,这个矩阵由 种字符填充构成,给定 个整数,即矩阵中每种字符构成的联通块个数, 需要你自己定,但是不能超过.
数据范围:
每个字符组成的联通块个数不超过100.
题解:
正着生成联通块似乎有些费劲,不如我们逆着思考问题将400个联通块生成,并逐渐减少联通块的个数。
A picture is worth a thousand words
任意发挥想象吧!
Code:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 100;
char str[maxn][maxn];
inline void init()
{
for(int i = 1;i <= 25; ++i)
for(int j = 1;j <= 25; ++j) str[i][j] = 'B';
for(int i = 1;i <= 25; ++i)
for(int j = 26;j <= 50;++j) str[i][j] = 'A';
for(int i = 26;i <= 50; ++i)
for(int j = 1;j <= 25; ++j) str[i][j] = 'C';
for(int i = 26;i <= 50; ++i)
for(int j = 26;j <= 50; ++j) str[i][j] = 'D';
int cnt = 0;
for(int i = 2;i < 25; i += 2)
{
for(int j = 2;j < 25; j += 2)
{
if(cnt >= 99) break;
++cnt;
str[i][j] = 'A';
}
}
cnt = 0;
for(int i = 2;i < 25; i += 2)
{
for(int j = 27;j < 50;j += 2)
{
if(cnt >= 99) break;
++cnt;
str[i][j] = 'B';
}
}
cnt = 0;
for(int i = 27;i < 50;i += 2)
for(int j = 2;j < 25; j += 2)
{
if(cnt >= 99) break;
++cnt;
str[i][j] = 'D';
}
cnt = 0;
for(int i = 27;i < 50;i += 2)
for(int j = 27;j < 50;j += 2)
{
if(cnt >= 99) break;
++cnt;
str[i][j] = 'C';
}
}
int main()
{
//freopen("input.in","r",stdin);
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("50 50\n");
init();
a = 100 - a, b = 100 - b, c = 100 - c, d = 100 - d;
int cnt_a = 0, cnt_b = 0, cnt_c = 0, cnt_d = 0;
for(int i = 2;i < 25; i += 2)
for(int j = 2;j < 25; j += 2)
{
if(cnt_a >= a) break;
++cnt_a;
str[i][j] = 'B';
}
for(int i = 2;i < 25; i += 2)
for(int j = 27;j < 50;j += 2)
{
if(cnt_b >= b) break;
++cnt_b;
str[i][j] = 'A';
}
for(int i = 27;i < 50;i += 2)
for(int j = 2;j < 25; j += 2)
{
if(cnt_d >= d) break;
++cnt_d;
str[i][j] = 'C';
}
for(int i = 27;i < 50;i += 2)
for(int j = 27;j < 50;j += 2)
{
if(cnt_c >= c) break;
++cnt_c;
str[i][j] = 'D';
}
for(int i = 1;i <= 50; ++i)
{
for(int j = 1;j <= 50; ++j) printf("%c",str[i][j]);
printf("\n");
}
return 0;
}