题目链接:http://acm.tju.edu.cn/toj/showp2805.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1016 Accepted Runs: 684
We suppose the prairie dogs are perfect architects, and they build their house in the farmland. One day, the black-tailed prairie dogs assemble at the farmland to play a funny game. The prairie dogs stand in a line with the length of 3order. Each time the middle third of the line of prairie dogs are disappeared. They repeat until none of the prairie dogs next to each other.
For example, if the order is 3, the initial number of prairie dogs(stands by the mark '@') is 27(33 = 27):
@@@@@@@@@@@@@@@@@@@@@@@@@@@The middle third of prairie dogs are disappeared(replace '@' with space):
@@@@@@@@@ @@@@@@@@@and disappear the middle third of each piece of the line:
@@@ @@@ @@@ @@@and again:
@ @ @ @ @ @ @ @The process stops because none of the remaining prairie dogs next to each other. Only the final result should be displayed.
Input
Each line of input will be a single number between 0 and 10, inclusive, indicating the order. The input stops when EOF(end of file) is reached.Output
You must output of final result of the line of prairie dogs, followed by a newline. There is no whitespace before or after your output.Sample Input
0 1 3
Sample Output
@ @ @ @ @ @ @ @ @ @ @
Problem Setter: chhot@TJURocket
Source: TJU Programming Contest 2007 Preliminary
水题,上代码
#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;
string s;
int n;
void dog(int a){
if(s.length()>=(int)pow(3.0,n)){
s+="\0";
//cout<<s<<"haha"<<s.length()<<endl;
return ;
}
if(a==0){
return dog(1);
}
if(a==1){
string t=" ";
for(int i=1;i<s.length();i++)
t+=" ";
s+=t;
return dog(2);
}
if(a==2){
int length=s.length();
for(int i=0;i<length/2;i++)
s+=s[i];
//cout<<p<<"haha"<<s;
return dog(0);
}
}
int main(){
while(~scanf("%d",&n)){
s="@";
dog(0);
cout<<s<<endl;
}
}