답안 #3614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3614 2013-08-31T06:59:05 Z eldkqmfhf123 Divide into triangle (kriii1_D) C++
0 / 1
0 ms 2404 KB
#include<iostream>
#include<math.h>
#define oo 0x7fffffff
using namespace std;


double Dist[301][301];

double dist(int ax,int ay, int bx, int by)
{
	double a = (bx-ax)*(bx-ax);
	double b = (by-ay)*(by-ay);
	return sqrt(a+b);
}
int Data[901][2];
int visit[901];
int main()
{
	int n;
	cin >> n;
	int i,j;
	for(i=0;i<3*n;i++)
		cin >> Data[i][0] >> Data[i][1];

	n *= 3;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			Dist[i][j] = dist(Data[i][0],Data[i][1],Data[j][0],Data[j][1]);
		}
	}

	for(int t=0;t<n/3;t++)
	{
		for(i=0;i<n;i++)
		{
			if(visit[i])continue;
			double MIN = oo;
			int MINJ;
			for(j=0;j<n;j++)
			{
				if(visit[j])continue;
				if(i==j)continue;
				if(MIN > Dist[i][j])
				{
					MIN = Dist[i][j];
					MINJ = j;
				}
			}
			double MIN2 = oo;
			int MINJ2;
			for(j=0;j<n;j++)
			{
				if(visit[j])continue;
				if(i==j || MINJ == j)continue;
				if(MIN2 > Dist[i][j])
				{
					MIN2 = Dist[i][j];
					MINJ2 = j;
				}
			}

			cout << i+1 << " " << MINJ+1 << " " << MINJ2+1 << endl;
			visit[i]=1;
			visit[MINJ]=1;
			visit[MINJ2]=1;
			break;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2404 KB Output isn't correct
2 Halted 0 ms 0 KB -