[USACO5.1]Fencing the Cows
来源:互联网 发布:淘宝点客服没反应 编辑:程序博客网 时间:2024/05/21 17:52
裸的二维凸包
namespace point{ struct point { double x,y; point() { x=y=0; } point makepoint(double x,double y) { point k; k.x=x; k.y=y; return k; } point operator - (point a) { return makepoint(x-a.x,y-a.y); } }g[10010]; int len,s[10010]; bool cmp1(point a,point b) { return a.y<b.y; } bool cmp2(point a,point b) { return a.x*b.y<a.y*b.x; } bool cmp3(point c,point b,point a) { return !cmp2(a-c,b-c); } void insert(int x) { s[++len]=x; } void popfrom(int x) { while(len>2&&cmp3(g[x],g[s[len]],g[s[len-1]])) len--; } double sqr(double x) { return x*x; } double dis(point a,point b) { return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); } double calc() { double ans=dis(g[s[1]],g[s[len]]); fr(i,2,len) ans+=dis(g[s[i]],g[s[i-1]]); return ans; }}int n;int main(){ n=read(); point::point *a=point::g; fr(i,1,n) scanf("%lf%lf",&(a+i)->x,&(a+i)->y); sort(a+1,a+n+1,point::cmp1); fd(i,n,1) a[i]=a[i]-a[1]; sort(a+2,a+n+1,point::cmp2); fr(i,1,2) point::insert(i); fr(i,3,n) { point::popfrom(i); point::insert(i); } printf("%.2lf\n",point::calc()); return 0;}
阅读全文
1 0
- [USACO5.1]Fencing the Cows
- usaco5.1.1 Fencing the Cows
- P2742 [USACO5.1]圈奶牛Fencing the Cows
- [luogu2742]:[USACO5.1]圈奶牛Fencing the Cows
- USACO5.1.1 Fencing the Cows (fc)
- USACO5.1.1 Fencing the Cows(fc)
- 凸包——Luogu2742 [USACO5.1]圈奶牛Fencing the Cows
- [USACO5.1]圈奶牛Fencing the Cows(凸包模板)
- 太感动了!第一次自己打出了USACO的题~ [USACO5.1]圈奶牛Fencing the Cows
- usaco 5.1.1 Fencing the Cows
- Fencing the Cows
- usaco fencing the cows
- Section 5.1 Fencing the Cows
- JZOJ1312.【USACO题库】5.1.1 Fencing the Cows圈奶牛
- USACO Section 5.1 Fencing the Cows
- USACO Fencing the Cows 解题报告
- USACO 5.1.1 Fencing the Cows 圈奶牛 题解与分析
- C++&Pascal——【USACO 5.1.1】——Fencing the Cows
- 读书:鲁迅的《故事新编》
- Kafka 0.10.1.1 特点
- DBCP建立数据连接池
- centos学习笔记(2)
- Tcp、Http网络协议
- [USACO5.1]Fencing the Cows
- 吉哥系列故事——完美队形II (manacher 的 变形应用)
- HDU 6033 Add More Zero(取对数求一个数长度)
- GridSearchCV用法
- java 通过jmx获取active mq队列消息
- 【Java多线程】多线程死锁
- linux下拷贝某一时间段的文件
- 剑指offer_数组---二维数组中的查找
- Shiro第六篇【验证码、记住我】