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 ...
随机推荐
- super()和this()的区别
1)调用super()必须写在子类构造方法的第一行,否则编译不通过.每个子类构造方法的第一条语句,都是隐含地调用super(),如果父类没有这种形式的构造函数,那么在编译的时候就会报错. 2)supe ...
- Linux LVM过程问题
问题: 使用fdisk 修改完成磁盘后,在/etc/下没有出现新建的分区文件 解决: 重启系统 (好吧,这他妈也算解决方案~~)
- 如何查看JSP和Servlet版本
我们在java web开发的过程中,有时在资料上可能会提到环境所要支持的JSP,Servlet版本.如果版本低就可能出现测试错误. 方法:打开tomcat的common/lib 目录下,有两个JAR文 ...
- Openfire 的安装和配置
1. 下载最新的openfire安装文件 官方下载站点:http://www.igniterealtime.org/downloads/index.jsp#openfire 下载地址: Exe:htt ...
- IOS第18天(7,CAKeyframeAnimation-图标抖动)
*** #import "HMViewController.h" #define angle2radian(x) ((x) / 180.0 * M_PI) @interface H ...
- LaTex 基础
一.文档 \documentclass{article} %book, report, letter 二.宏包 \usepackage{amsmath} 三.正文 \begin{document} \ ...
- ArcGIS Server 增加缓存路径
Server缓存服务,由于缓存文件经常比较大,默认放在C盘下容易导致磁盘空间不够,因此Server提供了增加缓存路径的方法来解决该问题. 增加的路径有两种,一种是Server所在服务器增加一个和原缓存 ...
- iOS开发-Masonry简易教程
关于iOS布局自动iPhone6之后就是AutoLayOut,AutoLayOut固然非常好用,不过有时候我们需要在页面手动进行页面布局,VFL算是一种选择,如果对VFL不是很熟悉可以参考iOS开发- ...
- Spark1.6.2 java实现读取txt文件插入MySql数据库代码
package com.gosun.spark1; import java.util.ArrayList;import java.util.List;import java.util.Properti ...
- 【C++】类型转换(学习笔记)
1. 隐式类型转换,相关联的类型(e.g.int vs double)之间可以发生隐式类型转换. 比如,在条件中,非布尔类型转为布尔类型: 初始化时,初始值变为变量类型: 赋值时,右值变成左侧的类型: ...