叉积判断 POJ1696

 1 // 叉积判断 POJ1696
 2 
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <cstring>
 6 #include <cstdio>
 7 #include <vector>
 8 #include <cmath>
 9 #include <map>
10 using namespace std;
11 #define LL long long
12 typedef pair<int,int> pii;
13 const double inf = 123456789012345.0;
14 const int MOD = 998244353;
15 const int N = 2e5+10;
16 const int maxx = 200010; 
17 #define clc(a,b) memset(a,b,sizeof(a))
18 const double eps = 1e-8;
19 void fre() {freopen("in.txt","r",stdin);}
20 void freout() {freopen("out.txt","w",stdout);}
21 inline int read() {int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}return x*f;}
22 
23 int sgn(double x){
24     if(fabs(x) < eps)return 0;
25     if(x < 0)return -1;
26     else return 1;
27 }
28 
29 struct Point{
30     double x,y;
31     int index;
32     Point(){}
33     Point(double _x,double _y){
34         x = _x;y = _y;
35     }
36     Point operator -(const Point &b)const{
37         return Point(x - b.x,y - b.y);
38     }
39     double operator ^(const Point &b)const{
40         return x*b.y - y*b.x;
41     }
42     double operator *(const Point &b)const{
43         return x*b.x + y*b.y;
44     }
45 };
46 
47 double dist(Point a,Point b){
48     return sqrt((a-b)*(a-b));
49 }
50 
51 int pos;
52 Point p[110];
53 bool cmp(Point a,Point b){
54     double tmp=(a-p[pos])^(b-p[pos]);
55     if(sgn(tmp)==0){
56         return dist(a,p[pos])<dist(b,p[pos]);
57     }
58     else if(sgn(tmp)<0) return false;
59     else return true;
60 }
61 
62 int main(){
63     int T,n;
64     scanf("%d",&T);
65     while(T--){
66         scanf("%d",&n);
67         for(int i=0;i<n;i++){
68             scanf("%d%lf%lf",&p[i].index,&p[i].x,&p[i].y);
69             if(p[i].y<p[0].y||(p[i].y==p[0].y&&p[i].x<p[0].x)){
70                 swap(p[i],p[0]);
71             }
72         }
73         pos=0;
74         for(int i=0;i<n;i++){
75             sort(p+i,p+n,cmp);
76             pos++;
77         }
78         printf("%d",n);
79         for(int i=0;i<n;i++)
80             printf(" %d",p[i].index);
81         printf("\n");
82     }
83     return 0;
84 }

 

转载于:https://www.cnblogs.com/ITUPC/p/5865733.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值