# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3482 | hhosu107 | Divide into triangle (kriii1_D) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<math.h>
#define PI (4*atan(1.0))
int N;
int no[900];
int dot[900][2];
double angle[900];
int temp;
double temp2;
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]);
angle[i] = atan2((double)dot[i][1], (double)dot[i][0]);
if(angle[i] < 0.0)
angle[i] += 2 * PI;
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] > angle[k]){
swap2(&angle[j], &angle[k]);
swap(&dot[j][0], &dot[k][0]);
swap(&dot[j][1], &dot[k][1]);
swap(&no[j], &no[k]);
}
else if(angle[j] == angle[k]){
if(abs(dot[j][0]) > abs(dot[k][0])){
swap2(&angle[j], &angle[k]);
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;
}