POJ 2876 Cantoring Along
Description
- Start with a string of dashes, with length 3order
- Replace the middle third of the line of dashes with spaces. You are left with two lines of dashes at each end of the original string.
- Replace the middle third of each line of dashes with spaces. Repeat until the lines consist of a single dash.
For example, if the order of approximation is 3, start with a string of 27 dashes:
---------------------------
Remove the middle third of the string:
--------- ---------
and remove the middle third of each piece:
--- --- --- ---
and again:
- - - - - - - -
The process stops here, when the groups of dashes are all of length 1. You should not print the intermediate steps in your program. Only the final result, given by the last line above, should be displayed.
Input
Output
Sample Input
0
1
3
2
Sample Output
-
- -
- - - - - - - -
- - - - 【思路】:递归题,用时稍久,希望你写出用时更短的代码。我们可以将一个数组赋值为空格,然后对该数组进行分割,同样满足题意,每次丢掉中间的三分之一,然后递归循环此过程,将其划分的更小,直到分割到长度为1,结束返回。。
#include <iostream>
#include <cmath>
using namespace std; void along(int Along)
{
if(Along<)
{
cout<<'-';
}
else
{
if(Along>=)
along(Along/);
for(int i=;i<=Along/;i++)//这儿应该是 Along/3 假如是你之前的话 打印较多的空格 你仔细看一下
cout<<" ";
if(Along>=)
along(Along/);
}
} int main()
{
int n;
while(cin>>n)
{
int Along=(int)pow(3.0,n);
along(Along);
cout<<endl;
}
return ;
}
POJ 2876 Cantoring Along的更多相关文章
- POJ 2876
#include<iostream> #include<string> using namespace std; ]; int main() { //freopen(" ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
随机推荐
- Python之路(二)
(1)python的内置函数(BIF) python3中内置了70多个BIF,常用的几个有: list():创建一个新的空列表. range():输入次数参数,返回一个迭代固定次数的迭代器. enum ...
- 如何防御“神器”Mimikatz窃取系统密码?
Mimikatz是一款能够从Windows中获取内存,并且获取明文密码和NTLM哈希值的神器,本文将介绍如何防御这款软件获取密码. Mimikatz介绍 Mimikatz是一款能够从Windows认证 ...
- bzoj2743: [HEOI2012]采花--离线树状数组+差分
题目大意:给定一个区间,查询子区间里出现次数不小于二的数的个数 此题想了好久没想出来,后来是在网上学习的一个方法 首先按查询区间的右端点进行排序,按右端点从小到大处理 假设pre[a[i]]是与a[i ...
- db2数据库新手可能碰到的问题及详解(部分内容来自网络搜索)
一.db2安装好之后出现乱码,菜单栏呈现方框状,此时选择菜单第五项,点击选择下拉菜单中的最后一项,打开选择标签卡的第三项(字体),如果是无衬线都改为有衬线,如果是有衬线改为无衬线.乱码即可解决(网上一 ...
- js 字符串拼接
正常来说已经使用es6 的 模板了如`` //页面层 layer.open({ type: 1, content:`<div class="child_card"> & ...
- Mysql忽略文件名的安全编码
author:skatetime:2014/09/28 mysql如何删除以"#sql-"开头的临时表 现象:在重建索引后,发现Mysql服务器的磁盘空间快满了 在用如下命令重建索 ...
- c++20701除法(刘汝佳1、2册第七章,暴搜解决)
20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 输入正整数n,按从小到大的顺序输出所有 ...
- php中防盗链使用.htaccess
下面开始讲解:比如你的图片都在img目录下,那就在该目录下放一个名为 .htaccess 的文件,内容如下: php代码: 以下为引用的内容:RewriteEngine onRewriteCond % ...
- window常见事件
<script type="text/javascript"> /*onunload = function(){ alert("onunload run&qu ...
- BOM&Navigator对象
<!-- BOM:Brower Object Model 浏览器对象模型 这个模型方便操作浏览器 浏览器对应的对象就是windows对象,这个可以通过查阅DHTML API获得 --> & ...