ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1185. Wall

What's wrong with my program? Please help.. is it the 8-inch precision stuff i dont understand
Posted by Alyosha Popovich 27 Mar 2002 00:06
#include <stdio.h>
#include <math.h>

long X[1010], Y[1010];
int N, L;

int st[1002], ss;

long double R;

#define PI 3.14159265358979323846

#define det(x0, y0, x1, y1, x2, y2) ((x1-x0)*(y2-y0) - (x2-x0)*(y1-
y0))
#define cc(a, b, c) (det(X[a], Y[a], X[b], Y[b], X[c], Y[c]) >= 0)

void add(int x)
{
    while (ss > 1 && cc(st[ss-2], st[ss-1], x)) ss--;
    st[ss++] = x;
}

void solve()
{
    int i;
    for (ss = i = 0; i < N; i++)
        add(i);
    add(0);
    R = (long double) (2*PI)*(long double) L;
    for (i = 0; i < ss-1; i++)
        R += sqrtl((X[st[i]]-X[st[i+1]])*(X[st[i]]-X[st[i+1]])+(Y[st
[i]]-Y[st[i+1]])*(Y[st[i]]-Y[st[i+1]]));
}

void read_data()
{
    int i;
    scanf("%d %d", &N, &L);
    for (i = 0; i < N; i++)
        scanf("%ld %ld", X+i, Y+i);
}

void main()
{
    read_data();
    solve();
    printf("%.0Lf\n", R);
}