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 ...
随机推荐
- Android自定义View——自定义ViewPager
第一部分:自定义ViewGroup的使用,手势识别器和Scroller滑动 第二部分:处理滑动监听,处理滑动冲突,增加ViewPager的指示器 常见的滑动冲突:外部滑动方向和内部滑动方向不一 ...
- DRF源码-serializers
class BaseSerializer(Field) """ The BaseSerializer class provides a minimal class whi ...
- mysql初始化数据库建表脚本
set names utf8; set global validate_password.policy=LOW;set global validate_password.length=6;CREATE ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- VS2013 配置Mysql
1.添加mysql.h 对着项目右键,选择properties 双击C/C++,选择General,看到Additional Include Directories 编辑 点击文件夹的按钮 点击... ...
- openstack trove主要贡献公司-Tesora被Stratoscale收购
新闻链接:http://www.stratoscale.com/press/press-releases/stratoscale-acquires-database-as-a-service-prov ...
- h5-切割轮播图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 最短路问题--P4779 单源最短路(标准版)Dijkstra堆优化
题目背景 2018 年7月 19 日,某位同学在 NOI Day 1 T1 归程 一题里非常熟练地使用了一个广为人知的算法求最短路. 最终,他因此没能与理想的大学达成契约. 小 F 衷心祝愿大家不再重 ...
- 直击JDD | 王振辉:技术是驱动物流革新的第一要素
"从物流基础设施的大规模智能迭代到产业供应链的数字化升级,物流行业从大而重变得'举重若轻',技术是驱动物流革新的第一要素."11月19日,京东物流集团CEO王振辉在2019京东全球 ...
- Android 公告新闻消息资讯之垂直滚动效果
垂直滚动新闻栏的实现原理: 就是一个自定义的LinearLayout,并且textView能够循环垂直滚动,而且条目可以点击,显示区域最多显示2个条目,并且还有交替的属性垂直移动的动画效果,通过线程来 ...