码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-13 22:49:12      阅读:185      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!