[luogu2742]:[USACO5.1]圈奶牛Fencing the Cows
来源:互联网 发布:dns区域传输使用端口 编辑:程序博客网 时间:2024/05/01 23:09
传送门
突然心血来潮开始搞计算几何。。
首先肯定是凸包。。
直接贴代码吧。。。
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<cstdlib>#define ll long longusing namespace std;inline int read(){ int x=0;char ch=' ';int f=1; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')f=-1,ch=getchar(); while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); return x*f;}const int N=1e4+5;const double eps=1e-12;struct Point{ double x,y; Point(){} Point(double _x,double _y):x(_x),y(_y){}}p[N];inline bool operator == (const Point& a,const Point& b){ return fabs(a.x-b.x)<eps && fabs(a.y-b.y)<eps;}inline Point operator - (const Point& a,const Point& b){ return Point(a.x-b.x,a.y-b.y);}inline double operator * (const Point& a,const Point& b){ return (a.x*b.y)-(a.y*b.x);}inline bool cmp(const Point& a,const Point& b){ if(fabs(a.x-b.x)<eps)return a.y<b.y; return a.x<b.x;}inline double slope(const Point& a,const Point& b){ return (b.y-a.y)/(b.x-a.x);}inline double dis(const Point& a,const Point& b){ return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));}int n,s1[N],s2[N],top,len;int main(){ n=read(); for(int i=1;i<=n;i++)scanf("%lf %lf",&p[i].x,&p[i].y); sort(p+1,p+n+1,cmp); s1[++top]=1;s1[++top]=2; for(int i=3;i<=n;i++){ while(top>1 && (p[i]-p[s1[top]])*(p[s1[top]]-p[s1[top-1]])>0)top--; s1[++top]=i; } len=top; top=0; s2[++top]=n;s2[++top]=n-1; for(int i=n-2;i>=1;i--){ while(top>1 && (p[i]-p[s2[top]])*(p[s2[top]]-p[s2[top-1]])>0)top--; s2[++top]=i; } double ans=0; for(int i=1;i<len;i++)ans+=dis(p[s1[i]],p[s1[i+1]]); for(int i=1;i<top;i++)ans+=dis(p[s2[i]],p[s2[i+1]]); printf("%.2lf",ans); return 0;}
阅读全文
0 0
- [luogu2742]:[USACO5.1]圈奶牛Fencing the Cows
- 凸包——Luogu2742 [USACO5.1]圈奶牛Fencing the Cows
- P2742 [USACO5.1]圈奶牛Fencing the Cows
- [USACO5.1]圈奶牛Fencing the Cows(凸包模板)
- 太感动了!第一次自己打出了USACO的题~ [USACO5.1]圈奶牛Fencing the Cows
- [USACO5.1]Fencing the Cows
- JZOJ1312.【USACO题库】5.1.1 Fencing the Cows圈奶牛
- usaco5.1.1 Fencing the Cows
- 计算几何 usaco Fencing the Cows 圈奶牛
- USACO 5.1.1 Fencing the Cows 圈奶牛 题解与分析
- USACO5.1.1 Fencing the Cows (fc)
- USACO5.1.1 Fencing the Cows(fc)
- [USACO5.1.1] 圈奶牛
- 【USACO5.1.1】圈奶牛(BSOI2142)
- usaco 5.1.1 Fencing the Cows
- Fencing the Cows
- usaco fencing the cows
- Section 5.1 Fencing the Cows
- 比特币源码解读一
- 1124. Raffle for Weibo Followers (20)
- java发送qq消息到指定qq
- Cassandra_维护和调优
- 笔记-cross validation(交叉验证)
- [luogu2742]:[USACO5.1]圈奶牛Fencing the Cows
- 生物信息-004-Biopython从NCBI搜索和取回数据库记录
- File类--目录操作
- Spark性能优化:资源调优篇
- 杨辉三角如何实现
- 从FAT16开始认识文件系统《第一讲 DBR肢解它,哼》
- Apache
- 新路程------imx6 sd卡部分摘要
- 深入理解 JavaScript 异步系列(2)—— jquery的解决方案