U E D R , A S I H C RSS

Bee Maja/하기웅

이야기

30분 만에 푼만큼 소스도 알고리즘도 원시적이다^^
그래도 시간이 그렇게 많이는 안나와서 다행임^^ (0.016초)
나중에 다시 코딩해 볼 것!!

코드

~cpp
#include <iostream>
using namespace std;

int willy, direction, step, mNum;
int row, col;

void getMaja(int wNum)
{
	step=1;
	row=0; col=0;
	if(wNum==1)
	{
		cout << row << " " << col<<endl;
		return;
	}
	while(true)
	{
		if(3*step*step-8*step+6<=wNum && 3*step*step-7*step+5>wNum)
		{
			direction = 2;
			mNum = wNum - (3*step*step-8*step+6);
			break;
		}
		else if(3*step*step-7*step+5<=wNum && 3*step*step-6*step+4>wNum)
		{
			direction = 3;
			mNum = wNum - (3*step*step-7*step+5);
			break;
		}
		else if(3*step*step-6*step+4<=wNum && 3*step*step-5*step+3>wNum)
		{
			direction = 4;
			mNum = wNum - (3*step*step-6*step+4);
			break;
		}
		else if(3*step*step-5*step+3<=wNum && 3*step*step-4*step+2>wNum)
		{
			direction = 5;
			mNum = wNum - (3*step*step-5*step+3);
			break;
		}
		else if(3*step*step-4*step+2<=wNum && 3*step*step-3*step+1>wNum)
		{
			direction = 6;
			mNum = wNum - (3*step*step-4*step+2);
			break;
		}
		else if(3*step*step-3*step+1<=wNum && 3*(step+1)*(step+1)-8*(step+1)+6>wNum)
		{
			direction = 7;
			mNum = wNum - (3*step*step-3*step+1);
			break;
		}
		else
			step++;
	}


	if(direction==2)
	{
		col=step-1;
		while(mNum--)
			row--;
	}
	else if(direction==3)
	{
		row=-step+1;
		col=step-1;
		while(mNum--)
			col--;
	}
	else if(direction==4)
	{
		row=-step+1;
		while(mNum--)
		{
			row++;
			col--;
		}
	}
	else if(direction==5)
	{
		col=-step+1;
		while(mNum--)
			row++;
	}
	else if(direction==6)
	{
		row=step-1;
		col=-step+1;
		while(mNum--)
			col++;
	}
	else
	{
		row=step-1;
		if(mNum-->=1)
		{
			col++;
			while(mNum--)
			{
				row--;
				col++;
			}
		}
	}
	cout << row << " " << col <<endl;
}

int main()
{
	while(cin>>willy)
		getMaja(willy);
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:36
Processing time 0.0088 sec