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就行了,有空可以尝试一下
 
 
 
 
 
 

HDU-6708 Windows Of CCPC(打表,递归)的更多相关文章

  1. 【Windows Of CCPC HDU - 6708】【打表,找规律】

    题意分析 HDU - 6708 题意:给出一个整数k,要求你输出一个长和宽均为2^k^ 的符合要求的矩阵.比如k等于1时输出 \[ \begin{matrix} C & C \\ P & ...

  2. Java Windows下读取注册表的工具类

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  3. hdu 5802 Windows 10 贪贪贪

    传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...

  4. HDU 4548 美素数(打表)

    HDU  4548  美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目 ...

  5. WINDOWS NT操作系统的注册表文件

    WINDOWS NT操作系统的注册表文件 WINDOWS NT注册表文件分为系统文件和用户文件两类. 系统设置和缺少用户 配置数据存放在系统C:\Windows\System32\config文件夹下 ...

  6. ACM: HDU 2563 统计问题-DFS+打表

    HDU 2563 统计问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u HDU 2 ...

  7. hdu 4548 筛法求素数 打表

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4548 Problem Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题 ...

  8. hdu 1509 Windows Message Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...

  9. HDU 5597 GTW likes function 打表

    GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...

随机推荐

  1. UML-异常处理

    1.名词解释 缺陷(Fault):错误引起的行为.如:程序员拼写错了数据库名称 错误(Error):缺陷在运行系统中的表现.如:当使用拼写错误的名称调用数据库时,抛出数据库异常 故障(Failure) ...

  2. Java 性能优化:面向对象及基础类型使用优化

    性能优化是个大筐,很多东西都能往里面装.虽说性能优化的具体方面比较多,但万丈高楼从地起,这里还是从Java最基本的一些入门知识相关的使用优化进行一些做些总结和建议.如何连最基本的API使用都不会,或不 ...

  3. ADC分辨率

    转载:http://www.rationmcu.com/elecjc/1874.html 今天给大家简单介绍一下ADC器件的常识. ADC,模数转换器,功能是把模拟电压转换成数字量. 概念听的模糊,说 ...

  4. 多源D点(邻接表+bfs)

    [问题]给出一颗n个结点的树,树上每条边的边权都是1,这n个结点中有m个特殊点,请你求出树上距离这m个特殊点距离均不超过d的点的数量,包含特殊点本身. 输入: 输入第一行包含三个正整数,n.m.d分别 ...

  5. Spring Cloud Alibaba 教程 | 前世今生

    Spring Cloud Alibaba是什么 先来看一下官方是怎么定义Spring Cloud Alibaba的: Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案.此 ...

  6. 网页嵌 activeXForm 中显示fastReport

  7. Python 安装gevent,在导入gevent之后就报错了

    错误信息如下 RuntimeWarning: greenlet.greenlet size changed, may indicate binary incompatibility. Expected ...

  8. 量化交易alpha、beta、shape等基本概念梳理

    1.期货型基金(CTA)的 Alpha 和 Beta 是指什么?  https://zhuanlan.zhihu.com/p/20700337 1980S                       ...

  9. UOJ #2 【NOI2014】起床困难综合症

    这道题我们设两个bitset(N和Y) \(N_i = cal(i,0) , Y_i=cal(i,1)\) cal(i) 即第i位经过题目中的计算后所得出来的值 然后贪心.倒序循环i,考虑第i位如何决 ...

  10. Red Hat、Fedora和Ubuntu软件包操作

    五.Red Hat.Fedora和Ubuntu软件包操作对比 最后总结: 在 /etc/yum.conf 的 [main] 后面添加以下配置即可! 复制代码 代码如下: exclude=kernel* ...