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

Repeatedly WA on test 3. I think i'm gonna crack!
Posted by xerxe 17 Dec 2006 04:27
#define PI2 6.283185307179586476925286766559
#include <iostream>
#include <math.h>
using namespace std;

void main(){
    int N, i;
    float R, x[100], y[100], L;
    L=0.0f;
    cin>>N>>R;
    if (N==0){ cout<<"0"; return;}
    for(i=0; i<N; i++){
        cin>>float(x[i])>>float(y[i]);
        if (i) L+=sqrt( (x[i-1]-x[i])*(x[i-1]-x[i])+(y[i-1]-y[i])*(y[i-1]-y[i]) );
    }
    L+=sqrt( (x[i-1]-x[0])*(x[i-1]-x[0])+(y[i-1]-y[0])*(y[i-1]-y[0]) );
    L+=PI2*R;
    if (N==1) L=PI2*R;
    L*=100;
    L=int(L);
    L/=100;
    cout<<L;
}

On my tests, it works ok. The length is truncated, not rounded. It works for 0, 1, 2, ... nails. I can't see what's wrong. And it's getting quite frustrating.
If someone could help me with an idea as to why i get WA on test 3, I would remain in their debt.
Thanks.
Re: Repeatedly WA on test 3. I think i'm gonna crack!
Posted by Nechaev Ilya (Rybinsk SAAT) 18 Dec 2006 03:20
Use this for writing result:

printf("%.2f", L);

instead of

L*=100;
L=int(L);
L/=100;
cout<<L;

Edited by author 18.12.2006 03:23
Re: Repeatedly WA on test 3. I think i'm gonna crack!
Posted by xerxe 18 Dec 2006 18:56
Whew!! Thanks a lot. It worked. I had the same issue in another problem. I'll change there, too.
Again, thank you very much.
Re: Repeatedly WA on test 3. I think i'm gonna crack!
Posted by VorobeY1326 21 Oct 2009 00:16
Thank U!!!!!))
I has WA because of
L*=100;
L=int(L);
L/=100;
cout<<L;
not printf()
))
Re: Repeatedly WA on test 3. I think i'm gonna crack!
Posted by Azamat M 21 Oct 2009 00:47
what's wrong with this ?

var n,k: byte;
    r,x0,y0,x1,y1,x,y: Real;
    s: real;
begin
  readln(n,r);
  s:=r*6.28;
  if n=0 then s:=0;
  if n=2 then
  begin
    readln(x0,y0);
    readln(x1,y1);
    s:=s+2*sqrt(sqr(x1-x0)+sqr(y1-y0));
  end;
  if n>2 then
  begin
    readln(x0,y0);
    x:=x0;
    y:=y0;
    for k:=1 to n-1 do
    begin
      readln(x1,y1);
      s:=s+sqrt(sqr(x1-x0)+sqr(y1-y0));
      x0:=x1;
      y0:=y1;
    end;
    s:=s+sqrt(sqr(x-x0)+sqr(y-y0));
  end;
  writeln(int(s*100)/100:0:2);
end.

i got WA on test #3

i tried
writeln(s:0:2); also, got WA


Edited by author 21.10.2009 00:48