Issues 1115: DNA
Time limit: 1Sec Memory Limit: 128MB submission: 4026 Resolution: 1355
Title Description
Xiaoqiang had a habit of life sciences, he was always curious flowers and birds came from. Finally, Johnny in high school, access to the hallowed words --DNA. It has a structure of one of the double helix. This allows a tendon Xiaoqiang scratch the scalp, "if able to draw out just fine," Xiao Qiang shouted. Now you can help him.
Entry
Test input comprising a plurality of sets of data. The first integer N (N <= 15), N represents the number of groups, each group of data comprising two integers a, b. a represents the number of rows of a unit of DNA sequence, a is an odd number and 3 <= a <= 39. b represents repeatability (1 <= b <= 20).
Export
DNA shape of the output, there is a blank line between each output.
Sample input
2 3 1 5 4
Sample Output
X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
Ideas: a recursive analog output, there is a pit, that is, if not the first output, the first line of output will be less.
#include<iostream>
using namespace std;
int a;
void print( int n ,int f ,int noprint){
if( n==0 )
return ;
if( n== a/2+1 ){
print(n-1,0,noprint);
for( int i=1;i<=a;i++){
if( i==n )
printf("X");
else printf(" ");
}
printf("\n");
print(n-1,1,noprint);
}
else{
if( !f ){
print(n-1,f,noprint);
if( n==1 && noprint == 1 || n > 1){
for( int i=1;i<=a;i++){
if( i==n || a+1-i == n )
printf("X");
else printf(" ");
}
printf("\n");
}
}
else {
for( int i=1;i<=a;i++){
if( i==n || a+1-i == n )
printf("X");
else printf(" ");
}
printf("\n");
print(n-1,f,noprint);
}
}
}
int main(void){
int n;
cin>>n;
while(n--){
int b;
cin>>a>>b;
for( int i=1;i<=b;i++)
print(a/2+1,0,i);
printf("\n");
}
return 0;
}