传送门:http://codeforces.com/contest/989/problem/C

这是一个构造问题。

构造一张网格,网格中的字符为’A’、’B’、’C’、’D’,并且其连通块的个数分别为a、b、c、d。

首先我们可以考虑两种颜色的情形:

构造一张网格,网格中的字符为’0’、’1’,并且其连通块的个数分别为a、b,其中a、b均为正整数。于是,至少为’0’、’1’分别构造一个连通块;再分别以连通块为“网”,植入’1’、’0’,植入时应保证植入的点互不连通。如下图所示:

以上构造法可以推广至四种颜色的情况。如下图所示:

参考程序如下:

#include <bits/stdc++.h>
using namespace std; char g[][]; int main(void)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << << " " << << endl;
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) g[i][j] = 'A';
for (int j = ; j < ; j++) g[i][j] = 'B';
}
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) g[i][j] = 'C';
for (int j = ; j < ; j++) g[i][j] = 'D';
}
a--; b--; c--; d--;
int x, y;
x = ; y = ;
while (d) {
g[x][y] = 'D';
y += ;
if (y >= ) {
y = ;
x += ;
}
d--;
}
x = ; y = ;
while (c) {
g[x][y] = 'C';
y+= ;
if (y >= ) {
y = ;
x += ;
}
c--;
}
x = ; y = ;
while (b) {
g[x][y] = 'B';
y += ;
if (y >= ) {
y = ;
x += ;
}
b--;
}
x = ; y = ;
while (a) {
g[x][y] = 'A';
y += ;
if (y >= ) {
y = ;
x += ;
}
a--;
}
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) putchar(g[i][j]);
putchar('\n');
}
}

Codeforces 989C - A Mist of Florescence的更多相关文章

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

    C - A Mist of Florescence 把50*50的矩形拆成4块 #include<bits/stdc++.h> using namespace std; ],b[]; ][ ...

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

    C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. Codeforces Round #487 (Div. 2) A Mist of Florescence (暴力构造)

    C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces A Mist of Florescence

    A Mist of Florescence 题目大意: 事先告诉你每种颜色分别有几个联通块,构造一个不超过 \(50*50\) 的矩形.用 \(A,B,C,D\) 四种颜色来对矩形进行涂色使它满足要求 ...

  5. CF989C A Mist of Florescence (构造)

    CF989C A Mist of Florescence solution: 作为一道构造题,这题确实十分符合构造的一些通性----(我们需要找到一些规律,然后无脑循环).个人认为这题规律很巧妙也很典 ...

  6. 【题解】CF989C A Mist of Florescence

    [题解]CF989C A Mist of Florescence 题目大意: 让你构造一个\(n∗m\)矩阵,这个矩阵由4种字符填充构成,给定4个整数,即矩阵中每种字符构成的四联通块个数,\(n,m\ ...

  7. CF989C A Mist of Florescence 构造 思维好题 第八题

    A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. CF思维联系– Codeforces-989C C. A Mist of Florescence

    ACM思维题训练集合 C. A Mist of Florescence time limit per test 1 second memory limit per test 256 megabytes ...

  9. A Mist of Florescence CodeForces - 989C(思维构造)

    题意: 让你构造一个图,使得A,B,C,D的个数为给定的个数,上下左右连通的算一个. 哎呀 看看代码就懂了..emm..很好懂的 #include <bits/stdc++.h> usin ...

随机推荐

  1. IDEA中Spark往Hbase中写数据

    import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.io.ImmutableBytesWr ...

  2. 34.无废话ExtJs 入门教程十八[树:TreePanel]

    转自:https://www.cnblogs.com/iamlilinfeng/archive/2012/06/28/2566350.html 1. <!DOCTYPE html PUBLIC ...

  3. SQL常用指令集(Oracle)

    1. Select rownum(oracle) top(mysql): 用于规定返回指定数目的值 Where roenum < number 2. Like 用于在where子句搜索指定模式 ...

  4. 关于mfc添加热键

    对于mfc的添加热键的文章已经有很多了,我这里就简单的说一下并且说一些可能出的错误 首先在资源文件中添加ACCELERATOR然后在资源文件下的RC中找到ACCELERATOR的节点,打开后可以发现一 ...

  5. linux 定义变量 ,添加变量值

    1.设置值$name=test2. 输出变量的值 echo $echo $name3. 增加变量内容PATH=$PATH:/home/bin/testPATH="$PATH":/h ...

  6. [JOI2014] 小笼包

    题面 : https://www.ioi-jp.org/joi/2013/2014-yo/2014-yo-t6/2014-yo-t6.html 题解 dp + 康托展开 一看这题不知道怎么处理 只能枚 ...

  7. Android 性能优化(12)网络优化( 8)Monitoring the Battery Level and Charging State

    Monitoring the Battery Level and Charging State PreviousNext This lesson teaches you to Determine th ...

  8. Android 性能优化(8)网络优化( 4)Optimizing App-Initiated Network Use

    Optimizing App-Initiated Network Use This lesson teaches you to Batch and Schedule Network Requests ...

  9. 371 Sum of Two Integers 两整数之和

    不使用运算符 + 和-,计算两整数a .b之和.示例:若 a = 1 ,b = 2,返回 3. 详见:https://leetcode.com/problems/sum-of-two-integers ...

  10. 无法连接到已配置的web服务器

    问题:如题,asp.net WebForm的项目,在vs中选择aspx文件在浏览器中查看时候回报该错误. 网上最多的解决方案是防火墙的原因,说关闭防火墙就可以了.但问题是我另一个项目没有问题啊,所以不 ...