当前位置: 首页 > 工具软件 > Cube-J > 使用案例 >

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

谷泳
2023-12-01

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;
}




 类似资料: