In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:
CC
PC
And the 2-nd order CCPC window is shown in the figure:
CCCC
PCPC
PPCC
CPPC
We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as CC of order k, and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.
And now I have an order kk ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.
多组数据,每组输入一个数,输出对应窗口的图案。窗口是2的k次方大小。
错误思路:每行单独模拟,不是像正解一样一块块模拟。第一行全是C,2^(k-1)+1行是一半P一半C,然后再找规律。结果一直没搞明白,然后这题就没写出来。
正确思路:窗口图案除了第1个是固定的以外,后面的一块都可以看作左上、右上、右下分别有一个完全一样的前者,左下是右下每一行的取反(C、P相互对立)。例如,样例2可以理解为
CC CC
PC PC
PP CC(P和C相反,以此类推)
CP PC。
样例3可以理解为
CCCC CCCC
PCPC PCPC
PPCC PPCC
CPPC CPPC
PPPP CCCC
CPCP PCPC
CCPP PPCC
PCCP CPPC
模拟时可以代入数学中四个象限的概念,以左上为固定方向开始打印,那么左上角的点(x0,y0)就跟右上角的点(x0+2(k-1),y0)、右下角的点(x0+2(k-1),y0+2(k-1))对应的字母是完全一样的;左下角的点(x0,y0+2(k-1))是跟右下角,或者说是跟左上角是相反的。模拟时,可以使用数组,也可以使用结构体。
正确代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include