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 ...
随机推荐
- JDK源码阅读-------自学笔记(五)(浅析数组)
一.数组基础 1.定义和特点 数组也可以看做是对象,数组变量属于引用类型,数组中每个元素相当于该队形的成员变量,数组对象存储在堆中. 2.初始化数组 常用类初始化 // 整型初始化 int[] int ...
- vue实现CheckBox与数组对象绑定
实现需求: 实现一个简易的购物车,页面的表格展示data数据中的一个数组对象,并提供选中商品和全选商品checkbox复选框,页面实时显示选中商品的总金额: 分析: 1:使用v-for循环渲染arra ...
- 面向对象变成(OOP)-创建类和使用类
1.1.1对象的抽象:抽象是一种归纳或总结,对象是现实世界物体特征的实例. (1)一切皆是对象. (2)类是对象的抽象. 1.1.2 对象的使用: 当对象被抽象为类以后,就可以创建具体的实例来操作了. ...
- HTML5新标签使用及CSS选择器(伪类)
这些标签能够让搜索引擎更直接的解析页面内容. <header></header>语义:文档或者页面的头部 <nav></nav>语义:导航这两者不是组合 ...
- linux中nc命令
语法 nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o<输出文件>][-p<通信端口>][-s ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习: 表单验证
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- one_day_one_linuxCmd---光标快捷操作
<坚持每天学习一个 linux 命令,今天我们来学习 切换光标的常用命令> 摘要:最近经常使用 xshell 软件来远程连接各种机器,在 bin/bash 下输入各种命令,因为都是一些非常 ...
- opencv matchTemplate函数用法
模板匹配函数,就是在一幅图中,找到另外一幅的在本图的相似的地方 CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, ...
- Windows下将Python源代码.py文件封装成exe可执行文件方法
安装pyinstaller cmd中使用pip安装 pip install pyinstaller 同时会自动安装pywin32(pip真慢50M这里就走20KB),可以进行切换为国内源进行提速. 就 ...
- 88.QuerySet API使用详解:get_or_create和bulk_create方法
get_or_create 根据某个条件进行查找,如果找到了匹配的数据就会返回这条数据,如果没有找到匹配到的数据,就会创建一个.示例代码如下: from django.http import Http ...