输入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. php构造函数实例讲解

    PHP官网定义: 复制代码 代码如下: 构造函数是类中的一个特殊函数,当使用 new 操作符创建一个类的实例时,构造函数将会自动调用.当函数与类同名时,这个函数将成为构造函数.如果一个类没有构造函数, ...

  2. 越狱Season 1-Episode 20: Tonight

    Season 1, Episode 20: Tonight -Pope: I want him under 24hour surveillance. surveillance: 监视 保证24小时监视 ...

  3. DuiLib——第一篇UIManager

    DUiLib 源码分析 --以UiLib 1.01版为分析目标 -------------------------------------------------------------------- ...

  4. E:nth-child(n)实现奇偶匹配

    <style> li:nth-child(2n){color:#f00;} /* 偶数 */ li:nth-child(2n+1){color:#000;} /* 奇数 */ </s ...

  5. Netty系列之Netty可靠性分析

      作者 李林锋 发布于 2014年6月19日 | 29 讨论 分享到:微博微信FacebookTwitter有道云笔记邮件分享 稍后阅读 我的阅读清单   1. 背景 1.1. 宕机的代价 1.1. ...

  6. Linux-SSL和SSH和OpenSSH,OpenSSL有什么区别

    ssl是通讯链路的附加层.可以包含很多协议.https, ftps, ..... ssh只是加密的shell,最初是用来替代telnet的.通过port forward,也可以让其他协议通过ssh的隧 ...

  7. 非对称SVD电影推荐系统

    采用1M MovieLensz数据(80%train, 20%test, UserIDs range between 1 and 6040 ,MovieIDs range between 1 and ...

  8. Choosing proper innodb_log_file_size

    If you’re doing significant amount of writes to Innodb tables decent size of innodb_log_file_size is ...

  9. linux包-下载-curl与wget

    [root@localhost ~]# rpm -qa|grep curllibcurl-7.19.7-37.el6_4.x86_64python-pycurl-7.19.0-8.el6.x86_64 ...

  10. proBuilder编辑的模型变黑

    ----更正: 旧帖中方法有误,解决不了问题. 更正确法: 将proBuilder创建的模型的Static属性由“-”改为去掉勾选:   ----旧帖 proBuilder编辑的模型变黑解法: 1,U ...