您的位置:首页 > 编程语言 > Go语言

POJ2007 Scrambled Polygon

2014-04-27 10:00 337 查看
PS: 此题可以用凸包做,也可以用极角排序,关键是理解排序原理,题目说不会出现三点共线的情况。(Window 64bit %I64d, Linux %lld)

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

struct point {
long long x, y;
point(long long x=0, long long y=0):x(x),y(y) {}
};
point S;

point operator - (point A, point B) {
return point(A.x-B.x, A.y-B.y);
}
double Cross(point A, point B) {
return A.x*B.y - A.y*B.x;
}

bool cmp(point A, point B) {
return Cross(A-S, B-S)>0;
}
vector<point> v;
int main()
{
point t;
scanf("%I64d%I64d", &S.x, &S.y);
v.clear();
while(scanf("%I64d%I64d", &t.x, &t.y)!=EOF) {
v.push_back(t);
}
sort(v.begin(), v.end(), cmp);
printf("(0,0)\n");
int len = v.size();
for(int i = 0; i < len; i++) {
printf("(%I64d,%I64d)\n", v[i].x, v[i].y);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: