U E D R , A S I H C RSS

Dermuba Triangle/조현태

느낀점 및 설명

설겆이 하기 귀찮아서.. 또하나..^^

소스


~cpp
#include <iostream>
#include <Windows.h>
#include <math.h>

using namespace std;

POINT GetTrianglePoint(int houseNumber)
{
	POINT trianglePoint;
	trianglePoint.x = 0; trianglePoint.y = 0;
	
	for (; trianglePoint.y * trianglePoint.y <= houseNumber; ++trianglePoint.y);
	--trianglePoint.y;

	houseNumber -= trianglePoint.y * trianglePoint.y;

	for (trianglePoint.x = trianglePoint.y * (-1); 0 < houseNumber; ++trianglePoint.x)
	{
		--houseNumber;
	}

	return trianglePoint;
}

double GetHousePointX(POINT trianglePoint)
{
	return trianglePoint.x * 0.5;
}

double GetHousePointY(POINT trianglePoint)
{
	if ((0 == abs(trianglePoint.y) % 2 && 0 == abs(trianglePoint.x) % 2) ||
		(1 == abs(trianglePoint.y) % 2 && 1 == abs(trianglePoint.x) % 2))
	{
		return trianglePoint.y * (sqrt(3.0) / 2);
	}
	else
	{
		return ((trianglePoint.y - 1) * (sqrt(3.0) / 2)) + (sqrt(3.0) / 3);
	}
}

double GetHouseDistance(POINT trianglePointOne, POINT trianglePointAnother)
{
	return sqrt(pow(GetHousePointX(trianglePointOne) - GetHousePointX(trianglePointAnother), 2) +
		pow(GetHousePointY(trianglePointOne) - GetHousePointY(trianglePointAnother), 2));
}


void main()
{
	int houseNumberOne;
	int houseNumberAnother;

	while (	cin >> houseNumberOne >> houseNumberAnother)
	{
		printf("%.3f\n", GetHouseDistance(GetTrianglePoint(houseNumberOne), GetTrianglePoint(houseNumberAnother)));
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:07
Processing time 0.0239 sec