소감

2006-02-05 Accepted 0.010 Minimum

코드

~cpp
// 10233 - Dermuba Triangle
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>

inline void show(double value) { printf("%.3f\n",value); }

void process(int n, int m)
{
	int rootN = floor(sqrt(n));
	int rootM = floor(sqrt(m));
	double t1 = fabs(rootM - rootN + n - rootN * rootN - m + rootM * rootM) * 0.5; 
	double a, b, t2, t3;
	a = b = sqrt(3) / 6.0;
	if ((rootN & 0x1) != (n & 0x1))
		a *= 2.0;
	if (rootM != rootN)
	{
		if ((rootM & 0x1) == (m & 0x1))
			b *= 2.0;	
		t2 = a + b + (rootM - rootN - 1) * (sqrt(3) / 2.0);
	}
	else
	{
		if ((rootM & 0x1) != (m & 0x1))
			b *= 2.0;		
		t2 = fabs(a - b);
	}
	t3 = sqrt(t1 * t1 + t2 * t2);
	show(t3);
}

int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		if (n < m) 
			process(n, m);
		else 
			process(m, n);
	}
	return 0;
}
Retrieved from http://wiki.zeropage.org/wiki.php/DermubaTriangle/문보창
last modified 2021-02-07 05:23:06