poj 2007 Scrambled Polygon [极角排序]

来源:互联网 发布:windows资源管理器视图 编辑:程序博客网 时间:2024/05/21 10:08

题目链接:点击打开链接

 题目的意思很简单,就是从(0,0)开始,依次逆时针输出凸包的顶点。(没有任意三点在一条直线上,并且所有的点都只在三个象限中)。

我直接按照求凸包时候的方法来进行排序的,找到(0,0)点,然后逆时针输出。

所有的点都只能再斜率为1的两条线的一侧。

Code:

#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int N = 55;struct POINT{    double x, y;}p[N];double cross(POINT o, POINT a, POINT b){    return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);}bool cmp(POINT a, POINT b){    if(a.y < b.y || (a.y == b.y && a.x < b.x)) return true;    else return false;}bool cmp1(POINT a, POINT b){    if(cross(p[0], a, b) > 0) return true;    else return false;}int main(){    int n = 0;    while(~scanf("%lf %lf", &p[n].x, &p[n].y)){        n ++;    }    int ca = n, i;    sort(p, p + n, cmp);    sort(p + 1, p + n, cmp1);    for(i = 0; i < n; i ++){        if(p[i].x == 0 && p[i].y == 0)        break;    }    while(ca --){        printf("(%.0lf,%.0lf)\n", p[i % n].x, p[i % n].y);        i = (i + 1) % n;    }    return 0;}

G++提交了好多次,都是wa。最后的结论是,G++ 对于double的输入要%lf,而对于输出要%f。我擦,第一次听说这个,好吧,长见识了。

但对于C++ 不管是输入还是输出都是%lf。

0 0
原创粉丝点击