# 圈奶牛<计算几何><C++>

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct point{//x横坐标,y纵坐标.
double x;
double y;
}p[10000],chosen[10000];
bool cmp(point a,point b){
if(a.y==b.y)
return a.x<b.x;
else
return a.y<b.y;
}
double count(double x,double y){//计算连线长度,x为Δx,y为Δy.
return sqrt(pow(x,2)+pow(y,2));
}
double det(point o,point a,point b){//计算叉积,判断OA是否在OB逆时针方向.
return (a.y-o.y)*(b.x-o.x)-(a.x-o.x)*(b.y-o.y);
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>p[i].x>>p[i].y;
sort(p,p+n,cmp);
int choose=0;
for(int i=0;i<n;i++){
while(choose>=2&&det(chosen[choose-1],p[i],chosen[choose-2])<0)
choose--;
chosen[choose++]=p[i];
}
int mark=choose+1;
for(int i=n-2;i>=0;i--){
while(choose>=mark&&det(chosen[choose-1],p[i],chosen[choose-2])<0)
choose--;
chosen[choose++]=p[i];
}
double tot=0;
for(int i=0;i<choose-1;i++)
tot+=count(chosen[i].x-chosen[i+1].x,chosen[i].y-chosen[i+1].y);
printf("%.2f",tot);
return 0;
}

#### 计算几何 usaco Fencing the Cows 圈奶牛

2016-03-01 20:14:28

#### 【USACO】2002 Feb Cow Cycling 奶牛赛车

2016-11-08 13:51:45

#### usaco 2012 Open【Running Laps奶牛赛跑】

2016-11-01 20:58:58

#### [USACO5.1]圈奶牛Fencing the Cows（凸包模板）

2017-10-08 21:41:55

#### [USACO 2012 Open]Running Laps奶牛赛跑

2016-10-18 20:55:25

#### 奶牛交叉(C++)

2018-01-15 18:41:15

#### C++常用计算几何算法

2015-06-29 10:24:57

#### 迫不及待推荐一个C++计算几何库

2015-07-07 13:54:53

#### 计算几何几何函数库

2008-03-16 14:48:00

#### C++计算几何算法大全

2016-11-23 19:37:40