首页 > 其他 > 详细

poj2365---求多边形边长总和

时间:2015-06-13 22:46:39      阅读:210      评论:0      收藏:0      [点我收藏+]
技术分享
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define pi acos(-1)

struct point{
    double x,y;
}first,last,now;
double dist(struct point *a,struct point *b)
{
    return sqrt((a->x - b->x)*(a->x - b->x)+(a->y - b->y)*(a->y - b->y));
}

int main()
{
    int n,i;
    double ans=0.0,r;
    scanf("%d %lf",&n,&r);
    ans+=2*pi*r;
    scanf("%lf %lf",&first.x,&first.y);
    last=first;
    for(i=1;i<n;i++)
    {
        scanf("%lf %lf",&now.x,&now.y);
        ans+=dist(&last,&now);
        last=now;
    }
    ans+=dist(&first,&last);
    printf("%.2f\n",ans);
    return 0;
}
View Code

用结构存储一个点的x,y坐标

结构指针(p)做参数,p->成员名

(*p).成员

在结构指针做参数的函数头部这样写:

double a(struct point *p1,struct point *p2)

struct point 相当于类型(int)

poj2365---求多边形边长总和

原文:http://www.cnblogs.com/gabygoole/p/4574120.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!