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 ...
随机推荐
- List集合对象根据字段排序
//把需要比较的对象实现Comparable接口实现compareTo方法 public class Address implements Comparable<Address> { St ...
- Linux_shell脚本_遍历文件夹下所有文件
参考:lunar1983的专栏 实现:从给定目录树中grep出含制定字符串的行,并给出所在路径 代码如下所示: #!/bin/sh - if [ $# -ne 2 ] then echo " ...
- js 所有事件列表
javascript事件列表解说 事件 浏览器支持 解说 一般事件 onclick IE3.N2 鼠标点击时触发此事件 ondblclick IE4.N4 鼠标双击时触发此事件 onmousedown ...
- 屏蔽Enter触发的事件
无论是 <button type="button" onclick="console.log('123');">123</button> ...
- 使用花生壳6.5客户端FTP设置
1.打开FTP客户端—选项—参数选择 2.设置为主动模式(PORT) 3.连接FTP服务器 4.FTP连接成功
- Window7 驱动编程环境配置
1. 安装VS2010,WDK7.60(GRMWDK_EN_7600_1) 2. 新建VC 控制台项目(选择为空项目) 3. 新建项目配置“driver” ,点击下拉按钮-点击(配置管理器) 输 ...
- arrhelper::map
$array = [ ['id' => '123', 'name' => 'aaa', 'class' => 'x'], ['id' => '124', 'name' => ...
- 使用 readfile() 下载文件
下载图片 <?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File Tran ...
- Cocos2dx淌坑日记:粒子系统PositionType的正确使用
Cocos2dx中的粒子系统,有三种定位方式,对应于不同需求. 之前我有一个想做的效果,是类似彗星的扫尾.但是当父节点也就是CCLayer跟着物体移动的时候,发现尾巴并没有跟随CCLayer移动,而是 ...
- Codevs 1021 玛丽卡
Codevs 1021 玛丽卡 题目地址:http://codevs.cn/problem/1021/ 题目描述 Description 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他 ...