Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

printf确实慢一点,但是不会T,我157ms

Posted by KatrineYang at 2016-08-31 00:09:16 on Problem 2083 and last updated at 2016-08-31 00:11:16
In 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator