HDU-6708 Windows Of CCPC(打表,递归)
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


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 first line of input file is an integer T.
Then the T lines contains a positive integers k , (1≤k≤10)
Output
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 ;
}
#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 ;
}
HDU-6708 Windows Of CCPC(打表,递归)的更多相关文章
- 【Windows Of CCPC HDU - 6708】【打表,找规律】
题意分析 HDU - 6708 题意:给出一个整数k,要求你输出一个长和宽均为2^k^ 的符合要求的矩阵.比如k等于1时输出 \[ \begin{matrix} C & C \\ P & ...
- Java Windows下读取注册表的工具类
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...
- hdu 5802 Windows 10 贪贪贪
传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...
- HDU 4548 美素数(打表)
HDU 4548 美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目 ...
- WINDOWS NT操作系统的注册表文件
WINDOWS NT操作系统的注册表文件 WINDOWS NT注册表文件分为系统文件和用户文件两类. 系统设置和缺少用户 配置数据存放在系统C:\Windows\System32\config文件夹下 ...
- ACM: HDU 2563 统计问题-DFS+打表
HDU 2563 统计问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u HDU 2 ...
- hdu 4548 筛法求素数 打表
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4548 Problem Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题 ...
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- HDU 5597 GTW likes function 打表
GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are give ...
随机推荐
- python可移植支持代码;用format.节省打印输出参数代码;math模块;
1.多平台移植代码: #!/usr/bin/env python3 这一行比较特殊,称为 shebang 行,在 Python 脚本中,你应该一直将它作为第一行. 请注意行中的第一个字符是井号(#). ...
- java基础——既然有了字节流,为什么还要有字符流呢?
不管是文件读写还是网络发送接收,信息的最小存储单元都是字节,那为什么I/O流操作要分字节流操作和字符流操作呢? 字符流是由JVM将字节转换得到的,所以这个过程还是非常耗时的,同样假如我们不知道编码方式 ...
- Q1:Two Sum
1. Two Sum 官方的链接:1. Two Sum Description : Given an array of integers, return indices of the two numb ...
- transform—切割轮播图
效果演示: 1.结构分析 第一步:在一个div里面有显示图片的ul标签(1个)和左右切换的a标签(2个): 第二步:ul标签中有5个li标签,li标签浮动,每个li标签的宽度占ul宽度的五分之一,高度 ...
- 双向链表的双向冒泡排序 c++
#include<iostream> using namespace std; #define swap(a,b) {int t;t = a;a = b;b = t;} //节点类型的定义 ...
- Linux(CENTOS7) Nginx负载均衡简单配置
负载均衡的作用 1.转发功能 按照一定的算法[权重.轮询],将客户端请求转发到不同应用服务器上,减轻单个服务器压力,提高系统并发量. 2.故障移除 通过心跳检测的方式,判断应用服务器当前是否可以正常工 ...
- 转:以下是目前已经建立的sub一览 来自:https://zhuanlan.zhihu.com/p/91935757
转:以下是目前已经建立的sub一览 来自:https://zhuanlan.zhihu.com/p/91935757 作者: Lorgar 理工科 科学(和英文r/science一样,只接受论文讨论 ...
- vi_终端中的编辑器操作
vi -- 终端中的编辑器 目标 vi 简介 打开和新建文件 三种工作模式 常用命令 分屏命令 常用命令速查图 01. vi 简介 1.1 学习 vi 的目的 在工作中,要对 服务器 上的文件进行 简 ...
- 到头来还是逃不过Java - 流程控制
流程控制 没有特殊说明,我的所有这个系列的Java13的笔记都是从廖老师那里摘抄.总结过来的,侵删 引言 兜兜转转到了大四,学过了C,C++,C#,Java,Python,学一门丢一门,到了最后还是要 ...
- 即时函数(Immediate Functions)
1.即时函数的声明方法 即时函数(Immediate Functions)是一种特殊的JavaScript语法,可以使函数在定义后立即执行: (function () { alert('wat ...