U E D R , A S I H C RSS

Dermuba Triangle/허준수

== 소감 ==
오답 잡던 도중에 친구가 소주한잔 하자고 해서.. 일단 여기까지하고~
소주 마시던 중 격좌좌표를 기하좌표로 옮기는 과정을 생략한 것이 생각나서
술자리를 파한 후 취중 개코딩..-..ㅡ;; 빙고! ㅋㄷㅋㄷ

== 소스파일 ==
~cpp
#include <iostream>
#include <cmath>

using namespace std;

int ax1,ax2,ax3,ay1,ay2,ay3;
int bx1,bx2,bx3,by1,by2,by3;
double centroid_ax, centroid_ay, centroid_bx, centroid_by;

void findPoint()
{
	centroid_ax = (double)(ax1+ax2+ax3)/3;
	centroid_ay = (double)(ay1+ay2+ay3)/3;
	centroid_bx = (double)(bx1+bx2+bx3)/3;
	centroid_by = (double)(by1+by2+by3)/3;
                
centroid_ax = centroid_ax + (centroid_ay/2);
	centroid_ay = centroid_ay*sqrt(3.0)/2;
	centroid_bx = centroid_bx + (centroid_by/2);
	centroid_by = centroid_by*sqrt(3.0)/2;
}

int findRow(int x)
{
	int row = ceil(sqrt(x+1)) * (-1);
	return row ;
}

void findLength()
{
	cout.setf(ios::fixed, ios::floatfield);   
                cout.setf(ios::showpoint);   
                cout.precision(3); 
	cout << sqrt(pow((centroid_bx - centroid_ax), 2) + pow((centroid_by - centroid_ay), 2)) <<endl;
}

void process(int x, int y)
{
	int row_a = findRow(x);
	int row_b = findRow(y);
	
	if(row_a%2 == 0) {
		if(x%2 == 0) {
			ax1 = row_a;
			ax2 = row_a + 1;
			ax3 = row_a + 1;
		} else {
			ax1 = row_a + 1;
			ax2 = row_a;
			ax3 = row_a;
		}
	} else {
		if(x%2 == 0) {
			ax1 = row_a + 1;
			ax2 = row_a;
			ax3 = row_a;
		} else {
			ax1 = row_a;
			ax2 = row_a + 1;
			ax3 = row_a + 1;
		}
	}

	if(row_b%2 == 0) {
		if(y%2 == 0) {
			bx1 = row_b;
			bx2 = row_b + 1;
			bx3 = row_b + 1;
		} else {
			bx1 = row_b + 1;
			bx2 = row_b;
			bx3 = row_b;
		}
	} else {
		if(y%2 == 0) {
			bx1 = row_b + 1;
			bx2 = row_b;
			bx3 = row_b;
		} else {
			bx1 = row_b;
			bx2 = row_b + 1;
			bx3 = row_b + 1;
		}
	}

	int col_a = (x - pow((row_a+1), 2))/2;
	int col_b = (y - pow((row_b+1), 2))/2;
	
	if(row_a%2 == 0) {
		if(x%2 == 0) {
			ay1 = col_a+1;
			ay2 = col_a;
			ay3 = col_a+1;
		} else {
			ay1 = col_a;
			ay2 = col_a;
			ay3 = col_a+1;
		}
	} else {
		if(x%2 == 0) {
			ay1 = col_a;
			ay2 = col_a;
			ay3 = col_a +1;
		} else {
			ay1 = col_a +1;
			ay2 = col_a;
			ay3 = col_a +1;
		}
	}

	if(row_b%2 == 0) {
		if(y%2 == 0) {
			by1 = col_b+1;
			by2 = col_b;
			by3 = col_b+1;
		} else {
			by1 = col_b;
			by2 = col_b;
			by3 = col_b+1;
		}
	} else {
		if(y%2 == 0) {
			by1 = col_b;
			by2 = col_b;
			by3 = col_b+1;
		} else {
			by1 = col_b+1;
			by2 = col_b;
			by3 = col_b+1;
		}
	}

	findPoint();
	findLength();
}

int main()
{
	int x, y;
	while (cin >> x >> y)
		process(x, y);
		
	return 0;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:07
Processing time 0.0199 sec