poj1941-귀속

1358 단어
#include <stdio.h>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring> 
#include <cmath>
#define setbit(x,y) x|=(1<<(y)) // X Y 1
#define clrbit(x,y) x&=~(1<<(y)) // X Y 0
#define sf scanf
#define pf printf
#define INF 1 << 29
#define eps 1e-6
const double PI = acos(-1.0);               
#define lint __int64
#define LL long long 
#define MAXN 1e9 + 7
#define maxn 1005
//101^110=011  
#define ULLint unsigned long long //2^64-1>1.8*10^19 
#define clr(x) memset(x, 0, sizeof(x))
#define Clr(x) memset(x, -1, sizeof(x))

using namespace std;

char map[3000][3000];

void dfs(int n,int x,int y)
{
	int size;
	if(n==1)
	{
		map[x][y]=map[x-1][y+1]='/';
		map[x][y+3]=map[x-1][y+2]='\\';
		map[x][y+1]=map[x][y+2]='_';
		return;
	}
	size=pow(2.0,n-1);
	dfs(n-1,x,y);
	dfs(n-1,x-size,y+size);
	dfs(n-1,x,y+size*2);
}
int main()
{
	int i,j,n,size;
	while(scanf("%d",&n)&&n)
	{
		size=pow(2.0,n);
		memset(map,' ',sizeof(map));
		dfs(n,size,1);
		for (i=1;i<=size;i++)
		{
			for(j=1;j<=size*2;j++)
				printf("%c",map[i][j]);
			printf("
"); } printf("
"); } return 0; }

좋은 웹페이지 즐겨찾기