2019 CCPC网络赛——1007——Windows Of CCPC

Windows Of CCPC

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

 

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

CCCCCCCC

 

PCPCPCPC

PPCCPPCC

CPPCCPPC

PPPPCCCC

CPCPPCPC

CCPPPPCC

PCCPCPPC

 

AC代码:

#include 
#include 

using namespace std;

const int MAX = 1024+5;
char MAP[MAX][MAX];

int main(void)
{
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		
		MAP[1][1] = 'C';
		MAP[1][2] = 'C';
		MAP[2][1] = 'P';
		MAP[2][2] = 'C';
		
		int k = 1;//阶数
		for(int i=1; i<=n; i++){
			int x1 = pow(2,k);
			int x2 = pow(2,k-1);
			
			for(int i=1; i<=x2; i++){//右上角 
				for(int j=x2 + 1; j<=x1; j++){
					MAP[i][j] = MAP[i][j-x2];
				}
			}
			
			for(int i=x2 + 1; i<=x1; i++){//右下角 
				for(int j=x2 + 1; j<=x1; j++){
					MAP[i][j] = MAP[i-x2][j];
				}
			} 
			
			for(int i=x2 + 1; i<=x1; i++){//左下角 
				for(int j=1; j<=x2; j++){
					if(MAP[i-x2][j] == 'C'){
						MAP[i][j] = 'P';
					}
					if(MAP[i-x2][j] == 'P'){
						MAP[i][j] = 'C';
					}
				}
			}
			
			k++;
		}
		
		int x = pow(2,n);
		for(int i=1; i<=x; i++){
			for(int j=1; j<=x; j++){
				cout << MAP[i][j];
			}
			cout << endl;
		}		
	}
	return 0;
}

/*1007 AC代码*/

思路:

AA

BA

按照格式输出

你可能感兴趣的:(POJ)