极角排序合集

poj 2007

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

struct point{
    int x,y;
    bool operator<(point k)const{
        int t=k.y*x-k.x*y;
        return t>0?true:false;
    }
}p[100];

int main()
{
    int n=0;
    while(scanf("%d%d",&p[n].x,&p[n].y)!=EOF)n++;
    sort(p+1,p+n);
    for(int i=0;i<n;i++){
        printf("(%d,%d)\n",p[i].x,p[i].y);
    }
    return 0;
}

lightoj 1285 


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

const int maxn=2000+5;
struct point{
    int x,y,id;
    bool operator<(point b)const{
        return x==b.x?y<b.y:x<b.x;
    }
}p[maxn];

int len(int x,int y){
    return x*x+y*y;
}

bool cmp(point z,point k){
    int t=(k.y-p[0].y)*(z.x-p[0].x)-(k.x-p[0].x)*(z.y-p[0].y);
    if(t==0)return len(z.x-p[0].x,z.y-p[0].y)<len(k.x-p[0].x,k.y-p[0].y);
    return t>0;
}


int main()
{
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%d",&p[i].x,&p[i].y);
            p[i].id=i;
        }
        sort(p,p+n);
        sort(p+1,p+n,cmp);
        printf("Case %d:\n",cas);
        point tt=p[n-1];
        int pos=n-1;
        for(int i=n-2;i>=0;i--){
            int tmp=(tt.y-p[0].y)*(p[i].x-p[0].x)-(tt.x-p[0].x)*(p[i].y-p[0].y);
            if(tmp!=0){
                break;
            }
            pos=i;
        }
        if(pos==0){
            printf("Impossible\n");continue;
        }
        reverse(p+pos,p+n);
        for(int i=0;i<n;i++){
            printf("%d",p[i].id);
            if(i < n-1)printf(" ");
            else printf("\n");
        }
        //printf("\n");
    }
    return 0;
}


poj 1696 Space Ant


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

const int maxn=60+5;
int res[maxn];int pos;

struct point{
    int x,y,id;
    bool operator<(point b)const{
        return y==b.y?x<b.x:y<b.y;
    }
}p[maxn];

int len(int x,int y){
    return x*x+y*y;
}

bool cmp(point z,point k){
    int t=(k.y-p[pos].y)*(z.x-p[pos].x)-(k.x-p[pos].x)*(z.y-p[pos].y);
    if(t==0)return len(z.x-p[pos].x,z.y-p[pos].y)<len(k.x-p[pos].x,k.y-p[pos].y);
    return t>0;
}


int main()
{
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++){
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&p[i].id,&p[i].x,&p[i].y);
        }
        sort(p,p+n);
        pos=0;int k=0;
        for(int i=1;i<n;i++){
            sort(p+i,p+n,cmp);
            res[pos++]=p[k++].id;
        }
        res[pos++]=p[k++].id;
        printf("%d",k);
        for(int i=0;i<pos;i++){
            printf(" %d",res[i]);
        }
        printf("\n");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值