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

递归做的,780k,94MS

Posted by songzhenqi at 2011-08-01 11:09:04 on Problem 2083 and last updated at 2011-08-01 14:18:53
#include <iostream>
#include <cmath>
using namespace std;

int n;
char map[750][750];

void digui(int n,int x,int y)
{
	if(n==1)
		map[x][y] = 'X';
	else
	{
		int size = pow(3+0.0,n-2);
		digui(n-1,x,y);
		digui(n-1,x+2*size,y);
		digui(n-1,x+size,y+size);
		digui(n-1,x,y+2*size);
		digui(n-1,x+2*size,y+2*size);
	}
}
int main()
{
	int i,j;
	while(cin>>n && n!=-1)
	{
		int size = pow(3+0.0,n-1);
		for(i=1;i<=size;i++)
			for(j=1;j<=size;j++)
				map[i][j] = ' ';
		digui(n,1,1);
		for(i=1;i<=size;i++)
		{
			for(j=1;j<=size;j++)
				cout<<map[i][j];
			cout<<endl;
		}
		cout<<"-"<<endl;
	}
	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