cf 323A A. Black-and-White Cube 立体构造
1 second
256 megabytes
standard input
standard output
You are given a cube of size k × k × k, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face.
Your task is to paint each of k3 unit cubes one of two colours (black or white), so that the following conditions must be satisfied:
- each white cube has exactly 2 neighbouring cubes of white color;
- each black cube has exactly 2 neighbouring cubes of black color.
The first line contains integer k (1 ≤ k ≤ 100), which is size of the cube.
Print -1 if there is no solution. Otherwise, print the required painting of the cube consequently by layers. Print ak × k matrix in the first k lines, showing how the first layer of the cube should be painted. In the followingk lines print a k × k matrix — the way the second layer should be painted. And so on to the lastk-th layer. Note that orientation of the cube in the space does not matter.
Mark a white unit cube with symbol "w" and a black one with "b". Use the format of output data, given in the test samples. You may print extra empty lines, they will be ignored.
1
-1
2
bb
ww bb
ww
题目意思,输出一个k*k*k的立体模型,使每个b的旁边有2个b,每个k的旁边有2个k
题解:
题目说的输出描述有点问题,它说的是先输出你的第1层,再输出k层从1到k的你的模型。实际上只用输出你构造的模型的1-k层。
这里提供两种构造方法
第1种
bbwwbb
bbwwbb
wwbbww
wwbbww
bbwwbb
bbwwbb
这种就是4个4个的。。以后每层就把上一层取反就OK了
还有一种是
bbbbbb
bwwwwb
bwbbwb
bwbbwb
bwwwwb
bbbbbb
类似这种不断将最外层围起来的构造方式,同理,以后的每层就把上一层取反就OK了。。
构造方法不唯一的。
至于 k 为奇数时无解我无法证明这个。。。
/*
* @author ipqhjjybj
* @date 20130709
*
*/
#include <cstdio>
#include <cstdlib> int main(){
int k;
scanf("%d",&k);
if(k&1) {
puts("-1");
return 0;
}
for(int i=0;i<k;i++){
for(int j=0;j<k;j++){
for(int z=0;z<k;z++){
putchar(((j>>1)&1)^((z>>1)&1)^(i&1)?'w':'b');
}
putchar('\n');
}
putchar('\n');
}
return 0;
}
cf 323A A. Black-and-White Cube 立体构造的更多相关文章
- cf 323A A. Black-and-White Cube 立体构造 不知道为什么当k为奇数时构造不出来 挺有趣的题目吧
A. Black-and-White Cube time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CF 633 div1 1338 B. Edge Weight Assignment 构造
LINK:Edge Weight Assignment 这场当时没打 看到这个B题吓到我了 还好当时没打. 想了20min才知道怎么做 而且还不能证明. 首先考虑求最小. 可以发现 如果任意两个叶子节 ...
- CF 453C. Little Pony and Summer Sun Celebration
CF 453C. Little Pony and Summer Sun Celebration 构造题. 题目大意,给定一个无向图,每个点必须被指定的奇数或者偶数次,求一条满足条件的路径(长度不超\( ...
- electrica writeup
关于 caesum.com 网上上的题目,分类有Sokoban,Ciphers,Maths,Executables,Programming,Steganography,Misc.题目有点难度,在努力奋 ...
- Android 轮播图Banner切换图片的效果
Android XBanner使用详解 2018年03月14日 08:19:59 AND_Devil 阅读数:910 版权声明:本文为博主原创文章,未经博主允许不得转载. https://www. ...
- Unity3D Shader 入门
什么是Shader Shader(着色器)是一段能够针对3D对象进行操作.并被GPU所执行的程序,它负责将输入的Mesh(网格)以指定的方式和输入的贴图或者颜色等组合作用,然后输出.绘图单元可以依据这 ...
- Unity3D学习笔记(三十四):Shader着色器(1)
一.GPU:图形处理器,Graphics Processing Unit 显卡的处理器就是图形处理器.与CPU类似. GPU和CPU的区别? 1.CPU主要是为了串行指令设计,GPU则是为了大规模 ...
- 棋盘覆盖问题(算法分析)(Java版)
1.问题描述: 在一个2k×2k个方格组成的棋盘中,若有一个方格与其他方格不同,则称该方格为一特殊方格,且称该棋盘为一个特殊棋盘.显然特殊方格在棋盘上出现的位置有种情形.因而对任何 k≥0,有4k种不 ...
- Unity Shader基础
Unity Shader基础 先上代码,代码一般是这样的. void Initialization(){ //先从硬盘加载代码再加载到GPU中 string vertexShaderCode = Lo ...
随机推荐
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 采购订单me22n 或者me21n增强 (点击保存和回车)
IF_EX_ME_PROCESS_PO_CUST DATA:l_header TYPE mepoheader, l_item TYPE mepoitem. DATA:lt_items TYPE pur ...
- Python 学习入门(23)—— 进程
本文介绍Python的os包中有查询和修改进程信息的函数,Python的这些工具符合Linux系统的相关概念,所以可以帮助理解Linux体系. 1. 进程信息 os包中相关函数如下: uname() ...
- 让MFC程序隐藏运行界面
在MFC中隐藏运行界面确实花花点功力. 针对对话框程序,一种不是很好地实现方法是在OnPaint函数中添加如下代码: CWnd::ShowWindow(SW_HIDE); 添加后执行会发现屏幕会闪烁一 ...
- CSS 控制应为Html页面高度导致抖动的问题
在CSS中添加如下代码: html,body{ overflow-y:scroll;} html,body{ overflow:scroll; min-height:101%;} html{ over ...
- django url调度
Django的url配置相同遵循着DRY(dont repeat yourself)的规则.下面都是官方文档的样例: 首先介绍的是Django怎样处理http的请求: 1.在setting里定义ROO ...
- 跟我一起学extjs5(11--自己定义模块的设计)
跟我一起学extjs5(11--自己定义模块的设计) 从这一节開始我们来设计并完毕一个自己定义模块.我们先来确定一个独立的模块的所能定义的一些模块信息. 下面信息仅仅是我自己在开发过程中 ...
- java.lang.ClassCastException: sun.proxy.$Proxy11 cannot be cast to分析
报这个错,只有一个原因,就是你转化的类型不对. 如果你的类是一个单实体类,也就是没有继承或是接口别的类. public class HjmServiceImpl {} 那么这样写就可以: HjmSer ...
- js下读取input中的value值
很多人(包括我),总想像以前操作js一样,读取到input中的值:document.getElementById('').value; 结果事实证明这样读到得是null. eval(document. ...
- How a C++ compiler implements exception handling
Introduction One of the revolutionary features of C++ over traditional languages is its support for ...