답안 #3542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3542 2013-08-31T06:28:59 Z hhosu107 Divide into triangle (kriii1_D) C++
1 / 1
0 ms 1112 KB
#include<stdio.h>

int N;

#define T 900

int no[T];
int dot[T][2];
double angle[T][2];

void swap(int *, int *);
void swap2(double *, double *);

int main(){
	int i = 0;
	scanf("%d", &N);
	while(N--){
		do{
			scanf("%d %d", &dot[i][0], &dot[i][1]);
			if(dot[i][0] == 0) angle[i][1] += 0.5;
			else angle[i][0] = (double)dot[i][1] / (double)dot[i][0];
			if(angle[i][0] < 0.0) angle[i][1] += 1.0;
			if(dot[i][1] < 0 || (dot[i][1] == 0 && dot[i][0] < 0)) angle[i][1] += 1.0;
			i++;
			no[i - 1] = i;
		}while(i % 3);
	}
	int j, k;
	for(j = 0; j < i - 1; j++){
		for(k = j + 1; k < i; k++){
			if(angle[j][1] > angle[k][1]){
				swap2(&angle[j][0], &angle[k][0]);
				swap2(&angle[j][1], &angle[k][1]);
				swap(&dot[j][0], &dot[k][0]);
				swap(&dot[j][1], &dot[k][1]);
				swap(&no[j], &no[k]);
			}
			else if(angle[j][1] == angle[k][1]){
				if(angle[j][0] > angle[k][0]){
					swap2(&angle[j][0], &angle[k][0]);
					swap2(&angle[j][1], &angle[k][1]);
					swap(&dot[j][0], &dot[k][0]);
					swap(&dot[j][1], &dot[k][1]);
					swap(&no[j], &no[k]);
				}
				else if(angle[j][0] == angle[k][0]){
					if(dot[j][0] * dot[j][0] > dot[k][0] * dot[k][0]){
						swap2(&angle[j][0], &angle[k][0]);
						swap2(&angle[j][1], &angle[k][1]);
						swap(&dot[j][0], &dot[k][0]);
						swap(&dot[j][1], &dot[k][1]);
						swap(&no[j], &no[k]);
					}
				}
			}
		}
	}
	j = 0;
	do{
		printf("%d %d %d\n", no[3 * j], no[3 * j + 1], no[3 * j + 2]);
		j++;
	}while(j * 3 != i);
	return 0;
}

void swap(int *x, int *y){
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

void swap2(double *x, double *y){
	double temp;
	temp = *x;
	*x = *y;
	*y = temp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1112 KB Output is correct
2 Correct 0 ms 1112 KB Output is correct
3 Correct 0 ms 1112 KB Output is correct
4 Correct 0 ms 1112 KB Output is correct
5 Correct 0 ms 1112 KB Output is correct
6 Correct 0 ms 1112 KB Output is correct
7 Correct 0 ms 1112 KB Output is correct
8 Correct 0 ms 1112 KB Output is correct
9 Correct 0 ms 1112 KB Output is correct
10 Correct 0 ms 1112 KB Output is correct
11 Correct 0 ms 1112 KB Output is correct
12 Correct 0 ms 1112 KB Output is correct
13 Correct 0 ms 1112 KB Output is correct
14 Correct 0 ms 1112 KB Output is correct
15 Correct 0 ms 1112 KB Output is correct
16 Correct 0 ms 1112 KB Output is correct
17 Correct 0 ms 1112 KB Output is correct
18 Correct 0 ms 1112 KB Output is correct
19 Correct 0 ms 1112 KB Output is correct
20 Correct 0 ms 1112 KB Output is correct