poj 1113 Wall
来源:互联网 发布:自动化行业用单片机吗 编辑:程序博客网 时间:2024/06/05 15:48
凸包入门。点这里
画图就能看出来周长就是一个圆+凸包周长
大佬的模板
一次循环求上部
一次循环求下部
#include<iostream>#include<stdio.h>#include<math.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;struct node { double x;double y;}p[400005],s[400005];int n,m;int sq(int x){ return x*x;}double chaji(node a,node b){ return a.x*b.y-a.y*b.x;}double dist(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}node xl(node a,node b){ node c; c.x=a.x-b.x; c.y=a.y-b.y; return c;}bool cmp(node a,node b){ if(a.x==b.x) return a.y<b.y; else return a.x>b.x;}int main(){ int n,l; while(scanf("%d %d",&n,&l)!=EOF) { memset(s,0,sizeof(s)); for (int i=0;i<n;i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } sort(p,p+n,cmp); int tot=0; for (int i=0;i<n;i++) { while(tot>1 && chaji(xl(s[tot-1],s[tot-2]),xl(p[i],s[tot-2]))<=0) tot--; s[tot++]=p[i]; } int k=tot; for (int i=n-2;i>=0;i--) { while(tot>k && chaji(xl(s[tot-1],s[tot-2]),xl(p[i],s[tot-2]))<=0) tot--; s[tot++]=p[i]; } if(n>1) tot--; double ans=0.0; for (int i=0;i<tot;i++) { ans+=dist(s[i],s[i+1]); } ans+=2*l*3.1415926; printf("%.0lf\n",ans); } return 0;}
阅读全文
0 0
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 wall
- poj 1113 Wall
- POJ 1113 wall
- poj 1113 Wall
- POJ 1113 WALL
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113 Wall
- poj 1113 Wall
- POJ 1113(Wall-Quickhull)
- POJ 1113 Wall
- poj-1113-Wall
- poj 1113 Wall
- POJ 1113 Wall
- POJ 1113 Wall
- poj - 1113 - Wall
- Blockchain的鱼和熊掌系列(21)之 keccak(sha-3) linux 下使用
- MAVEN Scope使用
- 将工程部署在tomcat服务器上
- 二级列表的简单效果实现
- hdu6038 Function
- poj 1113 Wall
- 20个非常有用的Java程序片段 [转载自知乎.侵删]
- scikit-learn主要模块和基本使用方法
- Maven介绍,包括作用、核心概念、用法、常用命令、扩展及配置
- Maven3.5.0安装与配置+Eclipse应用
- ubuntu 解决E:无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系
- Unique Paths问题及解法
- POJ2387 Til the Cows Come Home [kuangbin] 最短路
- ElasticSearch与大数据的不解情缘