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 WA on 4 test? SPS
Posted by Дмитрий 17 Aug 2008 22:19
This code dont worked! Why?
I dont know what i should to change.


type
  TPoint = record
    X, Y: Extended;
    end;

var N, R: integer;
    Points: array of TPoint;
    Sum: Extended;

function GetR(Index: integer): Extended;
begin
  Result := sqrt(
    sqr(Points[Index].X - Points[Index + 1].X) +
    sqr(Points[Index].Y - Points[Index + 1].Y));
end;

var i: integer;
begin
  Readln(N, R);
  SetLength(Points, N + 1);

  for i := 0 to N - 1 do with Points[i] do Readln(X, Y);
  Points[N] := Points[0]; // зацикл

  Sum := 2*pi*R;
  for i := 0 to N - 1 do Sum := Sum + GetR(i);
  Writeln(Sum:0:2);
end.



Thanks;
Why WA on 4 test? SPS
Posted by Дмитрий 21 Aug 2008 13:55
I think that following formula correct:

Sum := 2*pi*R + R(1, 2) + R(2, 3) + ... + R(N - 1, N) + R(N, 0) ;

Where R(i, j) - is function which returns distance between i and j nail's.

Where i'm wrong?

Edited by author 21.08.2008 13:57

Edited by author 21.08.2008 13:57
Why WA on 4 test? SPS
Posted by Дмитрий 21 Aug 2008 13:59
Anybody, give me please same test's
Re: Why WA on 4 test? SPS
Posted by qwe (Dmitry) 4 Sep 2008 22:45
OOOOOOoo :). My solution is correct. :0
My bug was here
....
R: integer;
....

but should be float type. unattentive
Re: Why WA on 4 test? SPS
Posted by Dmitry 18 Feb 2009 18:27
thanks, my error was the same :)
Re: Why WA on 4 test? SPS
Posted by akoskm 18 Oct 2009 16:02
me too :D
thank you!
Re: Why WA on 4 test? Please help !
Posted by mirzauzairbaig 13 Jan 2010 04:49
//81674XO
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    double PI=acos(-1.0);
    int N; double r, perimeter;
    cin>>N>>r;
    double *pointx, *pointy;
    pointx = new double[N+1];
    pointy = new double[N+1];
    for(int a=0; a<N; a++){
            cin>>pointx[a]>>pointy[a];
        }
    pointy[N]= pointx[0];
    pointx[N] = pointy[0];
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    if(N==1){
        perimeter=2*PI*r;
        cout<<perimeter;

        }
    else{
    if(N==2){
        perimeter=2*(pow((pow((pointx[0]-pointx[1]),2)+pow((pointy[0]-pointy[1]),2)),0.5)) + 2*PI*r;
        cout<<perimeter;

    }
    else{
        double angle;
        for(int a=0; a<N; a++){
            perimeter += pow((pow((pointx[a]-pointx[a+1]),2)+pow((pointy[a]-pointy[a+1]),2)),0.5);
                }

            double p1x, p2x, p3x, p1y, p2y, p3y, m1, m2;

            p1x=pointx[N-1]; p2x=pointx[0]; p3x=pointx[1];
            p1y=pointy[N-1]; p2y=pointy[0]; p3y=pointy[1];
            if(p3x==p2x)
                m1=tan(PI/2.0);
            if(p2x==p1x)
                m2=tan(PI/2.0);
            if(p2x!=p3x)
                m1=(p3y-p2y)/(p3x-p2x);
            if(p2x!=p1x)
                m2=(p1y-p2y)/(p1x-p2x);
            angle = 2*PI - (PI + fabs(atan(m1)-atan(m2)));
            for(int a=1; a<N; a++){
                p1x=pointx[a-1]; p2x=pointx[a]; p3x=pointx[a+1];
                p1y=pointy[a-1]; p2y=pointy[a]; p3y=pointy[a+1];
            if(p3x==p2x)
                m1=tan(PI/2.0);
            if(p2x==p1x)
                m2=tan(PI/2.0);
            if(p2x!=p3x)
                m1=(p3y-p2y)/(p3x-p2x);
            if(p2x!=p1x)
                m2=(p1y-p2y)/(p1x-p2x);

                angle += 2*PI - (PI + fabs(atan(m1)-atan(m2)));
                }

            perimeter += r*angle;
            cout<<perimeter;
            }}
    return 0;}





// please run my program and also, for some test cases and check for difference in answers !!
I've got WA#3. Why?
Posted by VladimirZagorodskih 16 Jan 2010 15:58
program project1;
var
  n, i : shortint;
  r, res, x, y, x1, y1, x0, y0 : extended;
begin
  readln(n, r);
  readln(x, y);
  x0:=x;
  y0:=y;
  res:=2*pi*r;
  for i:=1 to n-1 do begin
    readln(x1, y1);
    res:=res+sqrt(sqr(x1-x)+sqr(y1-y));
    y:=y1;
    x:=x1;
  end;
  write((res+sqrt(sqr(x1-x0)+sqr(y1-y0))):1:2);
end.
Re: Why WA on 4 test? Please help !
Posted by WOVVAN 2 Feb 2010 01:00
pizdos u teb9 proga)) 9 dumau 4to delo nemnogo v kode)