C. A Mist of Florescence (构造)

  • 题目链接:http://codeforces.com/contest/989/problem/C
  • 题意:给你四个数:a, b, c, d,分别对应 ‘A’ , ‘B’ , ‘C’ , ‘D’。 让这些对应大写字母在一个n*m的二维图里的联通块个数等于其对应的数字。二维图的行数列数都是 1<= n,m <=50。构造好图后输出n和m的值,和构造好的二维图。
  • 算法:构造
  • 思路:直接设图的大小为 40*50。先把图填满,每个字母分别占10行。然后在这十行中填入与这十行字母不同的字母。

#include <bits/stdc++.h>
#define pi acos(-1)
#define fastcin ios::base_sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 1LL << 62;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;

char M[150][150];
int a[10];
void init()
{
    for(int k=0; k<4; k++){
        for(int i=0+k*10; i<k*10+10; i++){
            for(int j=0; j<50; j++) M[i][j] = 'A'+k;
        }
    }
    //for(int i=0; i<40; i++) printf("%s\n", M[i]);
}



int main()
{
    init();
    scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]);

    for(int k=0; k<4; k++){

        for(int i=k*10+1; i<k*10+10; i+=2){
            for(int j=0; j<49; j+=2){
                if(a[3-k] >1 ) a[3-k]--;
                else break;
                M[i][j] = 'A'+3-k;
            }
        }

    }
    printf("40 50\n");
    for(int i=0; i<40; i++) printf("%s\n", M[i]);
}

猜你喜欢

转载自blog.csdn.net/qq_37352710/article/details/80720792