HDU 6708 Windows Of CCPC

Windows Of CCPC

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Problem Description

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:

在这里插入图片描述

And the 2-nd order CCPC window is shown in the figure:

HDU 6708 Windows Of CCPC_第1张图片

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 C 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 k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.

Input

The input file contains T test samples.(1<=T<=10)

The first line of input file is an integer T.

Then the T lines contains a positive integers k , (1≤k≤10)

Output

For each test case,you should output the answer .

Sample Input

3
1
2
3

Sample Output

CC
PC
CCCC
PCPC
PPCC
CPPC
CCCCCCCC
PCPCPCPC
PPCCPPCC
CPPCCPPC
PPPPCCCC
CPCPPCPC
CCPPPPCC
PCCPCPPC

题意:

根据前一个图形推出后面一个的图形

思路:

假如我们把每个图形分成4块,可以看出,这4块左上,右上,右下和之前的上一个图形是一样的,但是左下是相反的。C改P,P改C。

#include 
#include 
#include 
using namespace std;
const int maxn = 1010;
string s[maxn];
int main() {
    ios::sync_with_stdio(false);
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < maxn; i++) s[i].clear();
        s[1] = "CC";
        s[2] = "PC";
        for (int k = 2; k <= n; k++) {
            int x = (1 << k);
            for (int i = 1; i <= x; i++) {
                for (int j = 0; j < 2; j++) {
                    if (i > x / 2 && j == 0) {
                        for (int l = 0; l < x / 2; l++) {
                            if (s[i - x / 2][l] == 'C') s[i] += 'P';
                            else s[i] += 'C';
                        }
                    }
                    else if (i <= x / 2 && j == 1) s[i] += s[i];
                    else if (i > x / 2 && j == 1) {
                        for (int l = 0; l < x / 2; l++) s[i] += s[i - x / 2][l];
                    }
                }
            }
        }
        for (int i = 1; i <= (1 << n); i++) {
            for (int j = 0; j < (1 << n); j++) {
                cout << s[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

你可能感兴趣的:(HDU)