CF 323A(Black-and-White Cube-构造法放4w饼)

A. Black-and-White Cube
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

The first line contains integer k (1 ≤ k ≤ 100), which is size of the cube.

Output

Print -1 if there is no solution. Otherwise, print the required painting of the cube consequently by layers. Print a k × k matrix in the first klines, showing how the first layer of the cube should be painted. In the following k lines print a k × k matrix — the way the second layer should be painted. And so on to the last k-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.

Sample test(s)
input
1
output
-1
input
2
output
bb
ww

bb
ww


构造解

根据样例:偶数时可构造由‘饼’

ww  bb

ww  bb

拼出来,注意向邻的饼不同


看起来:奇数无解


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<cctype>
#include<cassert>
#include<climits>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define RepD(i,n) for(int i=n;i>=0;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define MEMI(a) memset(a,127,sizeof(a))
#define MEMi(a) memset(a,128,sizeof(a))
#define INF (2139062143)
#define F (1000000009)
typedef long long ll;
int n;
int main()
{
   //freopen("CF323A.in","r",stdin);
   cin>>n;
   if (n%2) 
   {
      puts("-1");return 0;
   }
   else
   {
      For(k,n)
      {
         For(i,n)
         {
            For(j,n) if (((i-1)/2+(j-1)/2+k)%2) cout<<'b';else cout<<'w';cout<<endl;
         }
         cout<<endl;
      }
      
   }
   
   //while (1);
   return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值