http://acm.hdu.edu.cn/showproblem.php?pid=6708

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:

 

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


Sample Output

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

Source

 
这题比较麻烦的就是换行符的处理了,感觉可以用打表和递归做
 
 

递归

解题思路:

最开始是4个字符左下角那个和其余3个不一样,

用最初的可以拼成第2个,把第2个分成4部分,左下角和第一个相反,也就是P变为C,C变为P,其余相同。

一共要输出2^n行,那么可以一行一行的输出,假设我要输出总行为8行,现在要输出第1行,

那么其实是输出总行为4行的第1行输出两遍,

当输出左下角的部分时,这是总行为4行的相应行相反输出1遍,在输出1遍相同的。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
const int maxn=1e5+;
using namespace std;
//ios::sync_with_stdio(false);
// cin.tie(NULL); //n表示图案一共有n层,row表示目前的层数 ,f表示是正常输出还是反着输出
void solve(int n,int row,int f)
{
if(n==)
{
if(f==)
{
if(row==)
printf("CC");
else
printf("PC");
}
else
{
if(row==)
printf("PP");
else
printf("CP");
}
return ;
}
int t=row%(n/);//t表示该图案row行是上一阶的多少行
if(t==)
t=n/;
if(f==)
{
if(row>n*1.0/)
solve(n/,t,);
else
solve(n/,t,);
solve(n/,t,);
}
else if(f==)
{
if(row>n*1.0/)
solve(n/,t,);
else
solve(n/,t,);
solve(n/,t,);
}
} int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
n=<<n;
for(int i=;i<=n;i++)
{
solve(n,i,);
printf("\n");
}
}
return ;
}
 
STL打表
 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
const int maxn=1e5+;
using namespace std;
//ios::sync_with_stdio(false);
// cin.tie(NULL); vector<string> vt[]; int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); vt[].push_back("CC");
vt[].push_back("PC");
for (int i = ; i <= ; i++)
{
for (vector<string>::iterator it1 = vt[i - ].begin(); it1 != vt[i - ].end(); it1++)
{
vt[i].push_back(*it1 + *it1);
}
for (vector<string>::iterator it1 = vt[i - ].begin(); it1 != vt[i - ].end(); it1++)
{
string s1 = *it1;
string s2 = "";
for (string::iterator it2 = s1.begin(); it2 != s1.end(); it2++) {
if (*it2 == 'C')
s2 += 'P';
else
s2 += 'C'; }
vt[i].push_back(s2 + *it1);
}
}
int T;
cin >> T;
while (T--)
{
int i;
cin >> i;
for (vector<string>::iterator it1 = vt[i].begin(); it1 != vt[i].end(); it1++)
{
cout << *it1 << endl;
}
}
return ;
}
还可以根据行数找规律
提前打表G[2^10+1][2^10+1],输出时两个for 1->2^k就行了,有空可以尝试一下
 
 
 
 
 
 

最新文章

  1. CSS魔法堂:小结一下Box Model与Positioning Scheme
  2. DBA必备:MySQL数据库常用操作和技巧
  3. jQuery事件绑定on、off 和one,取代bind, live, delegate
  4. React Native For Android 架构初探
  5. Java Script基础(五) 内置对象Date
  6. cf702D Road to Post Office
  7. Effective JavaScript Item 30 理解prototype, getPrototypeOf和__proto__的不同
  8. Java集合中对象排序
  9. Eclipse中Ctrl+Alt+Down和Ctrl+Alt+Up不起作用
  10. 在CentOS 6上安装Apache和PHP
  11. 利用squid 搭建简单的透明代理服务器
  12. sql查询当前登陆人所管理的校区下的人员
  13. partial 的随笔
  14. kubernetes进阶之五:Replication Controller&amp;Replica Sets&amp;Deployments
  15. Layui使用table展示数据
  16. HDU - 4578 Transformation(线段树区间修改)
  17. Django开发笔记五
  18. DES加密模式详解
  19. 机器学习进阶-图像特征sift-SIFT特征点 1.cv2.xfeatures2d.SIFT_create(实例化sift) 2. sift.detect(找出关键点) 3.cv2.drawKeypoints(画出关键点) 4.sift.compute(根据关键点计算sift向量)
  20. OpenCV学习代码记录——canny边缘检测

热门文章

  1. Linux 正则表达式与文本处理器 三剑客
  2. 初学C#之变量、占位符、转义符、还有就是类型转换
  3. Windows下Nodejs的开发环境搭建
  4. delphi save .dfm to .txt
  5. page-break-before和page-break-after 实现分页打印
  6. vue点击变色
  7. vue累加计数器
  8. bootstrap 支持的JavaScript插件
  9. 光纤卡网卡的区别以及HBA的常规定义-----引自百度百科
  10. Codeforces Round #571 (Unrated for Div. 1+Div. 2)