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

Common Board

Why WA on problem 1020?!!! What's wrong? Help, please...
Posted by Osama Ben Laden 8 Feb 2002 16:12
#include <iostream.h>
#include <math.h>

int n;
long double r;
long double x[202];
long double y[202];
long double sum=0.0;

const long double pi = 3.141592654;
long double lex(int i, int j)
{
 return sqrtl((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
}
int main()
{
 cin>>n>>r; int i;
 for(i=0; i<n; i++) cin>>(x[i])>>(y[i]);
 for(i=0; i<n-1; i++) sum += lex(i,i+1);
 sum += lex(n-1,0);
 sum += 2*pi*r;
 cout.precision(2); cout.setf(ios::showpoint);
 cout<<(floor(sum*100)/100)<<'\n';
 return 0;
}
Re: Why WA on problem 1020?!!! What's wrong? Help, please...
Posted by Aidar 9 Feb 2002 06:00
> #include <iostream.h>
> #include <math.h>
>
> int n;
> long double r;
> long double x[202];
> long double y[202];
> long double sum=0.0;
>
> const long double pi = 3.141592654;
> long double lex(int i, int j)
> {
>  return sqrtl((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
> }
> int main()
> {
>  cin>>n>>r; int i;
>  for(i=0; i<n; i++) cin>>(x[i])>>(y[i]);
>  for(i=0; i<n-1; i++) sum += lex(i,i+1);
>  sum += lex(n-1,0);
>  sum += 2*pi*r;
>  cout.precision(2); cout.setf(ios::showpoint);
>  cout<<(floor(sum*100)/100)<<'\n';
>  return 0;
> }
>
Write In Pascal, please!
Accepted Source in Pascacal:
var
  r, P : extended;
  a : array [1..101] of record
    x, y : extended;
  end;
  n, i : byte;


begin
  ReadLn (n, r);
  for i := 1 to n do with a [i] do ReadLn (x, y);
  with a [n + 1] do begin
    x := a [1].x;
    y := a [1].y;
  end;
  P := 2 * pi * r;
  for i := 1 to n do
    P := P +
      sqrt (sqr (a [i + 1].x - a [i].x) + sqr (a [i + 1].y - a
[i].y));
  WriteLn (P:0:2);
end.