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 1020. Rope

why i got WA#3 ?
Posted by Dmitry Panyushkin 14 Sep 2010 00:59
Please help me.. What's wrong in this code?


#include <stdio.h>
#include <math.h>

#define MAX_COUNT 100
#define PI 2. * acos (0.)


struct vertices
{
  double x;
  double y;
};

double solve (struct vertices *vert, int n, double r);

int main ()
{
  struct vertices vert[MAX_COUNT];
  double r;
  double res;
  int n;
  int i;

  if (scanf ("%d", &n) != 1)
    return -1;
  if (n < 1 || n > MAX_COUNT)
    return -2;

  if (scanf ("%lg", &r) != 1)
    return -3;
  if (r < 0.)
    return -4;

  for (i = 0; i < n; i++){
    if (scanf ("%lg %lg", &vert[i].x, &vert[i].y) != 2)
      return -5;
    if (fabs (vert[i].x) > 101. || fabs (vert[i].y) > 101.)
      return -6;
  }

  res = solve (vert, n, r);

  res = (double)((int)(res * 100));
  res /= 100;

  printf ("%.2lf\n", res);

  return 0;
}

double solve (struct vertices *vert, int n, double r)
{
  double res = 0.;
  double abs_x, abs_y;
  int i, t;

  for (i = 0; i < n; i++){
    t = (i + 1) % n;
    abs_x = (vert[i].x - vert[t].x) * (vert[i].x - vert[t].x);
    abs_y = (vert[i].y - vert[t].y) * (vert[i].y - vert[t].y);
    res += sqrt (abs_x + abs_y);
  }

  res += r * PI * 2.;

  return res;
}