Cows POJ - 3348 

题意:求(int)凸包面积/50

关于求凸包面积的两种写法

第一种
ans.push_back(ans[0]);
for(int i=0;i<(int)ans.size()-1;++i)    res+=cross(ans[i],ans[i+1]);

第二种
for(int i=1;i<(int)ans.size()-1;++i)    res+=cross(ans[i]-ans[0],ans[i+1]-ans[0]);

第二种因为多了减法,时间上不如第一种快
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=3e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
int sign(double x){
    return abs(x)<1e-7?0:x<0?-1:1;
}
struct Point{
    double x,y;
    Point(double x=0.0, double y=0.0) : x(x), y(y) {}
    Point operator - (const Point &rhs) const{
        return Point(x-rhs.x,y-rhs.y);
    }
    bool operator == (const Point &rhs) const{
        return sign(x-rhs.x)==0&&sign(y-rhs.y)==0;
    }
    bool operator < (const Point &rhs)const{
        if(x==rhs.x)    return y<rhs.y;
        else    return x<rhs.x;
    }
};
typedef Point Vector;
double cross(Vector A,Vector B){
    return (double)A.x*B.y-(double)A.y*B.x;
}
int n;
typedef vector<Point> Polygon;
Polygon convex_hull(Polygon P) {
    sort(P.begin(), P.end());  //排序
    P.erase(unique(P.begin(), P.end()), P.end());  //删除重复点
    int n = P.size(), k = 0;
    Polygon Q(n*2);
    for (int i=0; i<n; ++i) {
        while (k > 1 && cross(Q[k-1]-Q[k-2], P[i]-Q[k-2]) <= 0) k--;
        Q[k++] = P[i];
    }
    for (int t=k, i=n-2; i>=0; --i) {
        while (k > t && cross(Q[k-1]-Q[k-2], P[i]-Q[k-2]) <= 0) k--;
        Q[k++] = P[i];
    }
    Q.resize(k);
    return Q;
}
int main(void){
    while(cin>>n){
        Polygon t;
        for(int i=1;i<=n;i++){
            double x,y;
            scanf("%lf%lf",&x,&y);
            t.push_back({x,y});
        }
        vector<Point> ans=convex_hull(t);
        double res=0.0;
        for(int i=0;i<(int)ans.size()-1;++i)    res+=cross(ans[i],ans[i+1]);
        if(res<0)   res=-res;
        res/=2.;
        printf("%d\n",(int)res/50);
    }
    return 0;
}