输入n

1 <= n <= 100

有一个n * n * n 的立方体,由n ^ 3 个1 * 1 * 1 的单位立方体构成

要用white 和 black 2种颜色来染这n ^ 3个立方体,要求:

白色的立方体恰好有2个相邻的白色立方体

黑色的立方体恰好有2个相邻的黑色立方体

无解的时候输出-1,有解的时候输出一种染色方案

solution:

n为奇数时,无解,输出 -1

n为偶数时,n = 2时的答案:

bb    ww

bb    ww

n > 2时,以n=2为中心向外面扩展,进行构造

如 n = 4时,:

wwww      bbbb     wwww     bbbb

wbbw       bwwb    wbbw      bwwb

wbbw       bwwb    wbbw      bwwb

wwww      bbbb     bbbb       bbbb

代码:

  //File Name: cf323A.cpp
//Author: long
//Mail: 736726758@qq.com
//Created Time: 2016年05月26日 星期四 10时05分30秒 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream> using namespace std; const int MAXN = ; char ans[MAXN][MAXN]; char get(int x){
if(x == ) return 'b';
return 'w';
} char get_c(char x){
if(x == 'w') return 'b';
return 'w';
} void update(int x,int y,char c){
for(int i=x;i<=y;i++){
ans[x][i] = c;
ans[i][x] = c;
ans[i][y] = c;
ans[y][i] = c;
}
} bool solve(int n){
if(n % ) return false;
int now = ;
for(int i=;i+i < n+;i++){
update(i,n+-i,get(now^=));
}
return true;
} int main(){
int n;
scanf("%d",&n);
if(!solve(n))
puts("-1");
else{
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
if(i % )
printf("%c",ans[j][k]);
else
printf("%c",get_c(ans[j][k]));
}
puts("");
}
puts("");
}
}
return ;
}

codeforces 323A. Black-and-White Cube 构造的更多相关文章

  1. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  2. Codeforces 610C:Harmony Analysis(构造)

    [题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样 ...

  3. Codeforces 804E The same permutation(构造)

    [题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...

  4. Codeforces 1276C/1277F/1259F Beautiful Rectangle (构造)

    题目链接 http://codeforces.com/contest/1276/problem/C 题解 嗯,比赛结束前3min想到做法然后rush不出来了--比赛结束后又写了15min才过-- 以下 ...

  5. Codeforces 989 P循环节01构造 ABCD连通块构造 思维对云遮月参考系坐标轴转换

    A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a ...

  6. codeforces 848A - From Y to Y(构造)

    原题链接:http://codeforces.com/problemset/problem/848/A 题意:让我们构造一个字符串.这里有一种操作:取走这个字符串的若干部分,分成两部分,然后将这两部分 ...

  7. Codeforces 512E - Fox And Polygon(构造)

    Codeforces 题面传送门 & 洛谷题面传送门 中规中矩的构造题一道. 首先考虑将两张图都向一个中间状态转化.方便起见我们取所有点都连向 \(1\) 号点的情形作为中间状态. 考虑怎样从 ...

  8. Codeforces 1491G - Switch and Flip(构造题)

    Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \( ...

  9. codeforces 477B B. Dreamoon and Sets(构造)

    题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. Kernel panic - not syncing: Attempted to kill init

    解决方法:系统启动的时候,按下‘e’键进入grub编辑界面,编辑grub菜单,选择“kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/log ...

  2. URAL 1004 Sightseeing Trip(最小环)

    Sightseeing Trip Time limit: 0.5 secondMemory limit: 64 MB There is a travel agency in Adelton town ...

  3. hdu1213 并查集

    题意:有 n 个朋友,他们可能相互认识,A 认识 B,B 认识 C,则 ABC 相互认识,现在给出他们的认识情况,相互认识的人坐一桌,否则需要分开坐,问至少需要多少桌. 其实就是问并查集的个数,在初始 ...

  4. android基础知识13:AndroidManifest.xml文件解析

    注:本文转载于:http://blog.csdn.net/xianming01/article/details/7526987 AndroidManifest.xml文件解析. 1.重要性 Andro ...

  5. Android Studio + gradle多渠道打包

    通过工具栏的Build->Build Apk 好像只能打包第一个Module(eclipse里面是Project的概念),怎么多渠道打包呢?目前好像只能一个一个的打 首先在清单文件里设置个变量: ...

  6. 网络-CIDR地址分类介绍

    CIDR(Classless Inter Domain Routing)改进了传统的IPv4地址分类.传统的IP分类将IP地址直接对应为默认的分类,从而将Internet分割为网络.CIDR在路由表中 ...

  7. Maximum number of WAL files in the pg_xlog directory (1)

      Guillaume Lelarge: Hi, As part of our monitoring work for our customers, we stumbled upon an issue ...

  8. Python合并两个numpy矩阵

    numpy是Python用来科学计算的一个非常重要的库,numpy主要用来处理一些矩阵对象,可以说numpy让Python有了Matlab的味道. 实际的应用中,矩阵的合并是一个经常发生的操作,如何利 ...

  9. 发现PDF Transformer+转换的图像字体小了如何处理

    ABBYY PDF Transformer+转换的原始图像字体太小怎么办?为了获得最佳文本识别效果,请用较高的分辨率扫描用极小字体打印的文档,否则很容易在转换识别时出错.下面小编就给大家讲讲该怎么解决 ...

  10. NET软件开发中的事务大全

      各种事务很全啊. 原文地址:http://www.cnblogs.com/ltp/archive/2009/06/17/1505304.html     1 .NET开发中的事务处理大比拼 之 S ...