传送门: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. TI BLE STACK - OSAL

    TI 的OSAL做的很不错,不过看起来也挺费劲可能自己水平太差吧,网上买的谷雨的开发板觉得确实挺不错的. 做点学习笔记,首先是记录OSAL里执行的顺序流程,主要是task ,event,message ...

  2. jQuery的each内部的break,continue

    // break, continue在each等迭代器里都不可用 // return false = break // return true = continue function isClicke ...

  3. LOJ#557. 「Antileaf's Round」你这衣服租来的吗(FHQ Treap+珂朵莉树)

    题面 传送门 题解 好吧我是不太会复杂度分析-- 我们对于每种颜色用一个数据结构维护(比方说线段树或者平衡树,代码里写的平衡树),那么区间询问很容易就可以解决了 所以现在的问题是区间修改,如果区间颜色 ...

  4. printf的整型

    参 数 说  明 %d 输出数字长为变量数值的实际长度 %md 输出m位(不足补空格,大于m位时按实际长度输出) %-md m含义同上.左对齐输出 %ld l(小写字母)表示输出“长整型”数据 %m1 ...

  5. 234 Palindrome Linked List 回文链表

    请检查一个链表是否为回文链表. 进阶:你能在 O(n) 的时间和 O(1) 的额外空间中做到吗? 详见:https://leetcode.com/problems/palindrome-linked- ...

  6. 转】 mysql5.6.12 for Linux安装

    原博文出自于: http://blog.csdn.net/book_mmicky/article/details/25714049 感谢! 1:上www.mysql.org下载64位版本mysql5. ...

  7. 151. [USACO Dec07] 建造路径

    ★★   输入文件:roads.in   输出文件:roads.out   简单对比 时间限制:1 s   内存限制:128 MB 译 by CmYkRgB123 描述 Farmer John 刚刚得 ...

  8. 关于Pyhton多线程同步队列的应用

    ''' 同步队列 put方法和task_done方法, queue有一个未完成任务数量num,put依次num+1, task依次num-1.任务都完成时任务结束. 1.创建一个 Queue.Queu ...

  9. 北大ACM(POJ1019-Number Sequence)

    Question:http://poj.org/problem?id=1019 问题点:打表. Memory: 392K Time: 16MS Language: C++ Result: Accept ...

  10. python学习笔记(2)——练习小程序之 " input " 隐藏陷阱

    练习小程序之 ----------" input " 隐藏陷阱 age=input('please enter your age:') if age>=18: print(' ...