叉积判断 POJ1696

时间:2024-10-23 15:06:44
 // 叉积判断 POJ1696

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const double inf = 123456789012345.0;
const int MOD = ;
const int N = 2e5+;
const int maxx = ;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int sgn(double x){
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
} struct Point{
double x,y;
int index;
Point(){}
Point(double _x,double _y){
x = _x;y = _y;
}
Point operator -(const Point &b)const{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b)const{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const{
return x*b.x + y*b.y;
}
}; double dist(Point a,Point b){
return sqrt((a-b)*(a-b));
} int pos;
Point p[];
bool cmp(Point a,Point b){
double tmp=(a-p[pos])^(b-p[pos]);
if(sgn(tmp)==){
return dist(a,p[pos])<dist(b,p[pos]);
}
else if(sgn(tmp)<) return false;
else return true;
} int main(){
int T,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%lf%lf",&p[i].index,&p[i].x,&p[i].y);
if(p[i].y<p[].y||(p[i].y==p[].y&&p[i].x<p[].x)){
swap(p[i],p[]);
}
}
pos=;
for(int i=;i<n;i++){
sort(p+i,p+n,cmp);
pos++;
}
printf("%d",n);
for(int i=;i<n;i++)
printf(" %d",p[i].index);
printf("\n");
}
return ;
}