CF989C A Mist of Florescence 构造 思维好题 第八题
Posted l609929321
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF989C A Mist of Florescence 构造 思维好题 第八题相关的知识,希望对你有一定的参考价值。
"I‘ve been here once," Mino exclaims with delight, "it‘s breathtakingly amazing."
"What is it like?"
"Look, Kanno, you‘ve got your paintbrush, and I‘ve got my words. Have a try, shall we?"
There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.
The wood can be represented by a rectangular grid of nn rows and mm columns. In each cell of the grid, there is exactly one type of flowers.
According to Mino, the numbers of connected components formed by each kind of flowers are aa, bb, cc and dd respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.
You are to help Kanno depict such a grid of flowers, with nn and mm arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.
Note that you can choose arbitrary nn and mm under the constraints below, they are not given in the input.
The first and only line of input contains four space-separated integers aa, bb, cc and dd (1≤a,b,c,d≤1001≤a,b,c,d≤100) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.
In the first line, output two space-separated integers nn and mm (1≤n,m≤501≤n,m≤50) — the number of rows and the number of columns in the grid respectively.
Then output nn lines each consisting of mm consecutive English letters, representing one row of the grid. Each letter should be among ‘A‘, ‘B‘, ‘C‘ and ‘D‘, representing Amaranths, Begonias, Centaureas and Dianthuses, respectively.
In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).
5 3 2 1
4 7
DDDDDDD
DABACAD
DBABACD
DDDDDDD
50 50 1 1
4 50
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ABABABABABABABABABABABABABABABABABABABABABABABABAB
BABABABABABABABABABABABABABABABABABABABABABABABABA
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
1 6 4 5
7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD
In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.
题意: 给你A,B,C,D连通量的数目(连通量指上或下或左或右有连接),要你给出一个矩阵(给出的矩阵长宽小于等于50)满足这样的要求
引入别人博客的一张图
图中说明了一切 将你的矩阵四分,分别填充B,A,D,C,然后在这四个矩阵中按要求填充
#include <map> #include <set> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <cstring> #include <iostream> #include <algorithm> #define debug(a) cout << #a << " " << a << endl using namespace std; const int maxn = 1e2 + 10; const int mod = 1e9 + 7; typedef long long ll; char mapn[maxn][maxn]; void myfill( ll xs, ll ys, ll xe, ll ye, char c ) { for( ll i = xs; i <= xe; i ++ ) { for( ll j = ys; j <= ye; j ++ ) { mapn[i][j] = c; } } } int main(){ std::ios::sync_with_stdio(false); ll a, b, c, d; while( cin >> a >> b >> c >> d ) { a --, b --, c --, d --; myfill( 0, 0, 24, 24, ‘B‘ ); myfill( 0, 25, 24, 49, ‘A‘ ); myfill( 25, 0, 49, 24, ‘D‘ ); myfill( 25, 25, 49, 49, ‘C‘ ); for( ll i = 0; i <= 24; i ++ ) { for( ll j = 0; j <= 24; j ++ ) { if( i % 2 && j % 2 && a ) { mapn[i][j] = ‘A‘; a --; } } } for( ll i = 0; i <= 24; i ++ ) { for( ll j = 25; j <= 49; j ++ ) { if( i % 2 == 0 && j % 2 == 0 && b ) { mapn[i][j] = ‘B‘; b --; } } } for( ll i = 25; i <= 49; i ++ ) { for( ll j = 0; j <= 24; j ++ ) { if( i % 2 && j % 2 && c ) { mapn[i][j] = ‘C‘; c --; } } } for( ll i = 25; i <= 49; i ++ ) { for( ll j = 25; j <= 49; j ++ ) { if( i % 2 == 0 && j % 2 == 0 && d ) { mapn[i][j] = ‘D‘; d --; } } } cout << "50 50" << endl; for( ll i = 0; i <= 49; i ++ ) { cout << mapn[i] << endl; } } return 0; }
以上是关于CF989C A Mist of Florescence 构造 思维好题 第八题的主要内容,如果未能解决你的问题,请参考以下文章
CF989C A Mist of Florescence (构造)
Codeforces 989C A Mist of Florescence 构造
Codeforces A Mist of Florescence
Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)