TOJ 2805.Prairie dogs III
2016-09-03 19:19
316 查看
题目链接:http://acm.tju.edu.cn/toj/showp2805.html
2805. Prairie dogs III
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1016 Accepted Runs: 684
The lovely prairie dogs come to our sight again! The black-tailed prairie dog is a large, burrowing, ground squirrel belonging to a group of four other prairie dog species found only in North America. The black-tailed
prairie dog is the most abundant and widely distributed prairie dog.
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.
Problem Setter: chhot@TJURocket
Source: TJU
Programming Contest 2007 Preliminary
Submit List
Runs Forum Statistics
水题,上代码
#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;
}
}
2805. Prairie dogs III
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1016 Accepted Runs: 684
The lovely prairie dogs come to our sight again! The black-tailed prairie dog is a large, burrowing, ground squirrel belonging to a group of four other prairie dog species found only in North America. The black-tailed
prairie dog is the most abundant and widely distributed prairie dog.
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
Submit List
Runs Forum Statistics
水题,上代码
#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;
}
}
相关文章推荐
- TOJ 4080 find the princessIII(圆和直线相交)
- zoj 2818 Prairie dogs IV
- 叠罗汉III之推箱子
- LeetCode_OJ【337】 House Robber III
- TOJ 2772.Parallelogram
- 买卖股票的最佳时机 III
- TOJ 3313.Calculation(欧拉函数、费马定理)
- LeetCode 260. Single Number III 解题报告
- LeetCode[216] Combination Sum III
- LeetCode No.337 House Robber III
- Best Time to Buy and Sell Stock III -- LeetCode
- Leetcode之SingleNumber I/II/III
- 437_Path_Sum_III
- 123. Best Time to Buy and Sell Stock III
- 437. Path Sum III
- uC/OS iii(三)任务管理之任务状态
- ucosiii中断管理特性
- SPOJ GSS3 Can you answer these queries III
- leetcode---Contains Duplicate III
- 216. Combination Sum III