| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
printf确实慢一点,但是不会T,我157msIn Reply To:printf,TLE, putchar ,0ms Posted by:10142130255 at 2015-09-25 23:16:08 > ...
#include <iostream>
#include <stdio.h>
using namespace std;
char fractal[729][729];
int p3[8] = {0,1,3,9,27,81,243,729};
void setBlank(int startX, int startY, int dim){
for(int i = 0; i < p3[dim]; i++){
for(int j = 0; j < p3[dim]; j++){
fractal[startX+i][startY+j] = ' ';
}
}
}
void fillFractal(int startX, int startY, int dim){
if(dim == 1){
fractal[startX][startY] = 'X';
return;
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if((i+j)%2 == 0) fillFractal(startX+i*p3[dim-1], startY+j*p3[dim-1], dim-1);
else setBlank(startX+i*p3[dim-1], startY+j*p3[dim-1], dim-1);
}
}
}
void printFractal(int startX, int startY, int dim){
for(int i = 0; i < p3[dim]; i++){
for(int j = 0; j < p3[dim]; j++){
printf("%c", fractal[startX+i][startY+j]);
}
printf("\n");
}
}
int main() {
while(1){
int n;
scanf("%d", &n);
if(n <= 0) return 0;
fillFractal(0,0,n);
printFractal(0,0,n);
printf("-\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator