C. A Mist of Florescence

题目链接

Codeforces Round #??487(Div. 2)--C. A Mist of Florescence

题解

简单题/难题(也可能是傻逼题)。题意大概是使用四种颜色对一块区域染色,使每种颜色的联通块的数量为所要求的数量。
乍一看好像很麻烦的样子,实际上注意到数据规模,每种颜色的联通块的数量至少为1,至多为100,而允许的区域数量有50*500,那就可以玄学AC了。首先对四种颜色各染一大块,然后往第一种颜色里填充第二种颜色,第二种颜色里填充第三种颜色,以此类推直到符合要求即可。

代码

#include <cstdio>
#include <cmath>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
char s[55][55];
int a, b, c, d;
int main() {
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 50; j++) {
            if (i / 12 == 0) s[i][j] = 'A';
            else if (i / 12 == 1) s[i][j] = 'B';
            else if (i / 12 == 2) s[i][j] = 'C';
            else s[i][j] = 'D';
        }
    }
    int temp = 0;
    for (int i = 1; i <= 10; i+=2) {
        for (int j = 1; j < 49; j++) {
            if (!d)break;
            temp++;
            if (temp % 2) { s[i][j] = 'D'; d--; }
        }
    }
    temp = 0;
    for (int i = 13; i <= 22; i+=2) {
        for (int j = 1; j < 49; j++) {
            if (!a)break;
            temp++;
            if (temp % 2) { s[i][j] = 'A'; a--; }
        }
    }
    temp = 0;
    for (int i = 25; i <= 37; i+=2) {
        for (int j = 1; j < 49; j++) {
            if (!b)break;
            temp++;
            if (temp % 2) { s[i][j] = 'B'; b--; }
        }
    }
    temp = 0;
    for (int i = 37; i <= 47; i+=2) {
        for (int j = 1; j < 49; j++) {
            if (!c)break;
            temp++;
            if (temp % 2) { s[i][j] = 'C'; c--; }
        }
    }
    cout << 50 << ' ' << 50 << endl;
    for (int i = 0; i < 50; i++) {
        cout << s[i] << endl;
    }
}

标签: graphs, constructive algorithms

添加新评论