U E D R , A S I H C RSS

Dermuba Triangle/하기웅

== 이야기 ==
처음 생각을 잘못해서 잘못된 곳에서 너무 많이 헤맷다.~~
0.010초 Accepted~

소스

~cpp
#include <iostream>
#include <cmath>
using namespace std;

int first, second, sExp, eExp, sNum, eNum;
double row, col;

double getDistance(int s, int e)
{
	sExp = 0; eExp= 0;
	row=0.0; col=0.0;
	if(s==e)
		return 0.0;
	sExp = floor(sqrt(s));
	sNum = s - sExp*sExp;

	eExp = floor(sqrt(e));
	eNum = e - eExp*eExp;

	row = (sNum-eNum+(eExp-sExp))/2.0;

	if(eExp-sExp==0)
	{
		if((eNum-sNum)%2==0)
			col = 0;
		else
			col = sqrt(3.0)/6;
	}
	else
	{
			if(sNum%2==0)
				col += sqrt(3.0)/6;
			else
				col += sqrt(3.0)/3;
			if(eNum%2==0)
				col += sqrt(3.0)/3;
			else
				col += sqrt(3.0)/6;
			col+=sqrt(3.0)*(eExp-sExp-1)/2;
	}
	return sqrt(row*row+col*col);
}

int main()
{
	cout.setf(ios::fixed, ios::floatfield); 
    cout.setf(ios::showpoint); 
    cout.precision(3);

	while(cin>>first>>second)
	{
		if(second>first)
			cout << getDistance(first, second)<< endl;
		else
			cout << getDistance(second, first)<< endl;
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:07
Processing time 0.0107 sec