2019中国大学生プログラムデザインコンテスト(CCPC)-ネット選抜試合1007

11986 ワード

Windows Of CCPC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2830 Accepted Submission(s): 2018
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:
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 CCCC PCPC PPCCPPCC CPPCCPPC PPCCCC CPPCPC CCPPCC
考え方:辛抱強く法則を探す.各図は4つの部分に分かれている.左下隅はテンプレートと逆になり、残りはテンプレートと変わりません.考察:2 D配列の付与.コード#コード#
#include
#include
#include
using namespace std;
char a[1025][1025];
int main() {
     
    int T;
    cin >> T;
    int k;
    while(T--) {
     
        int n;
        cin >> n;
        k = 1;
         memset(a, 'C', sizeof(a));
        while(n--) {
     
            k *= 2;
            for(int i = 0; i < k; i++)
                for(int j = 0; j < k; j++)
                    if(i < k / 2 && j >= k / 2)
                        a[i][j] = a[i][j - k / 2];
                    else if(i >= k / 2 && j >= k / 2)
                        a[i][j] = a[i - k / 2][j - k / 2];
                    else if(i >= k / 2 && j < k / 2) {
     
                        a[i][j] = a[i - k / 2][j];
                    }
            for(int i = 0; i < k; i++)
                for(int j = 0; j < k; j++)
                    if(i >= k / 2 && j < k / 2) {
     
                        if(a[i][j] == 'C')
                            a[i][j] = 'P';
                        else
                            a[i][j] = 'C';
                    }


        }
        for(int i = 0; i < k; i++) {
     
            {
     for(int j = 0; j < k; j++)
                cout << a[i][j];}
        cout << endl;
        }
    }
    return 0;
}