ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1020. Ниточка

Why WA on 4 test? SPS
Послано Дмитрий 17 авг 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
Послано Дмитрий 21 авг 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
Послано Дмитрий 21 авг 2008 13:59
Anybody, give me please same test's
Re: Why WA on 4 test? SPS
Послано qwe (Dmitry) 4 сен 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
Послано Dmitry 18 фев 2009 18:27
thanks, my error was the same :)
Re: Why WA on 4 test? SPS
Послано akoskm 18 окт 2009 16:02
me too :D
thank you!
Re: Why WA on 4 test? Please help !
Послано mirzauzairbaig 13 янв 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?
Послано VladimirZagorodskih 16 янв 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 !
Послано WOVVAN 2 фев 2010 01:00
pizdos u teb9 proga)) 9 dumau 4to delo nemnogo v kode)