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 <iostream>
#include <cmath>

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

按照格式输出

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值