约瑟夫环问题(结构体指针实现)
来源:互联网 发布:数据工程师是干嘛的 编辑:程序博客网 时间:2024/06/09 23:37
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>using namespace std;typedef struct{double x,y;}P;typedef struct{int s,t;double k,l;}E;int n,top;double sum;P p[10010];E e[20020];bool comp(const P &a,const P &b){return a.x<b.x;}double dist(int a,int b){return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));}double slope(int a,int b){if (p[b].x-p[a].x==0) return 0;return (p[b].y-p[a].y)*1.0/(p[b].x-p[a].x);}int main(){freopen("fc.in","r",stdin);freopen("fc.out","w",stdout);int i,j;scanf("%d",&n);for (i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);sort (p+1,p+n+1,comp);i=1;while (i<n) {j=i+1;e[++top].s=i;e[top].t=j;e[top].l=dist(i,j);e[top].k=slope(i,j);while (top>1&&e[top-1].k>e[top].k) {top--;e[top].t=e[top+1].t;e[top].l=dist(e[top].s,e[top].t);e[top].k=slope(e[top].s,e[top].t);}i++;}while (top>0) sum+=e[top--].l;i=1;while (i<n) {j=i+1;e[++top].s=i;e[top].t=j;e[top].l=dist(i,j);e[top].k=slope(i,j);while (top>1&&e[top-1].k<e[top].k) {top--;e[top].t=e[top+1].t;e[top].l=dist(e[top].s,e[top].t);e[top].k=slope(e[top].s,e[top].t);}i++;}while (top>0) sum+=e[top--].l;printf("%.2f\n",sum);return 0;}
0 0
- 约瑟夫环问题(结构体指针实现)
- 约瑟夫环问题(结构体指针实现)
- 结构体指针实现插入排序和解决约瑟夫环问题
- [静态指针] 约瑟夫问题
- C语言指针实现循环报数问题(简单约瑟夫环问题)
- luogu--约瑟夫 指针实现
- 约瑟夫环问题的实现
- 类实现 约瑟夫环问题
- 编程实现约瑟夫环问题
- java实现约瑟夫环问题
- java实现约瑟夫环问题
- 约瑟夫环问题编程实现
- Java实现约瑟夫环问题
- 约瑟夫环问题--java实现
- 编程实现约瑟夫环问题
- Java实现约瑟夫环问题
- 约瑟夫问题、约瑟夫环
- 结构体指针问题
- 【第一行代码】Android中UI总结
- 导弹砸向YZR
- TCPCOPY的使用
- swift获取屏幕分辨率
- 广告网络中的常见名词
- 约瑟夫环问题(结构体指针实现)
- Cadence SPB 16. 6 安装步骤
- spy memcache 客户端使用体会
- cmake交叉编译配置
- 解决树莓派安装mysql后外部无法连接问题
- Java习惯用法总结
- SVN检出项目后报build.properties does not exit完整版解决方案
- AC自动机入门
- HDU 2767 Proving Equivalences(强连通分量)