[ create a new paste ] login | about

Link: http://codepad.org/wZEHQcro    [ raw code | output | fork ]

C++, pasted on Dec 10:
// ただの多角形とのこと。
// 題意に複素数は全く関係ありませんので、
// 相応しい構造体名、構造体メンバ名に変えました。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define N   (100)
struct pt {
    double x,y;
    pt(){};
    pt(double a,double b) { x=a; y=b; };
    double Len() { return sqrt(x*x+y*y); };
};
pt operator - (pt p0, pt p1) { return pt(p0.x-p1.x, p0.y-p1.y); }
int main(void) {
    pt      a[N+1];
    int     i;
    double  sum,b,c;
    srand(time(NULL));
    for (i=0 ; i<N ; i++) {
        while (!(b=rand()));
        while (!(c=rand()));
        a[i] = pt((double)rand()/b,(double)rand()/c);
    }
    a[N] = a[0]; sum = 0;
    for (i=1 ; i<=N ; i++)  sum += (a[i]-a[i-1]).Len();
    printf("%f\n",sum);
    return 0;
}


Output:
1
1214.297878


Create a new paste based on this one


Comments: