573 - The Snail

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Tanu
Learning poster
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

573 Sample Input Output plz

Post by Tanu »

Is there anyone tell what critical in this problem??
Is related with floating point error??
What the the success means?
passed>=height or passed>height
And
Failed means?
passed <= 0 or passed < 0

Sample Input Output plz...
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

I think there is no tricky input. You can try the input output set...
Input:

Code: Select all

2 2 2 20
8 6 5 30
97 56 3 10
56 3 1 5
85 26 19 10
59 17 13 11
97 73 23 17
0 0 0 0
Output:

Code: Select all

failure on day 2
failure on day 3
success on day 2
failure on day 32
failure on day 7
failure on day 6
success on day 2
Passed means current height > well height
Failed means current height < 0

Hope it helps.
Ami ekhono shopno dekhi...
HomePage
Tanu
Learning poster
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

Hi

Post by Tanu »

Thanx
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

I strongly disagree with this advice:
Try considering all input as floating point value.
Note that there is no need for floating point arithmetic at all. Instead of dividing something, multiply the rest.

Darko
Chirag Chheda
Learning poster
Posts: 74
Joined: Sat Jun 21, 2008 12:24 pm
Location: India

Re: 573 The Snail Why WA ?

Post by Chirag Chheda »

Code: Select all

Removed
Thanx to Jan :D
Last edited by Chirag Chheda on Fri Jun 27, 2008 8:08 am, edited 1 time in total.
Chirag Chheda
Learning poster
Posts: 74
Joined: Sat Jun 21, 2008 12:24 pm
Location: India

Re: 573 The Snail Why WA ?

Post by Chirag Chheda »

Can someone plz reply..
Thanx in advance
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 573 The Snail Why WA ?

Post by Jan »

Convert the real numbers to integers (by multiplying a common constant). Then use integer arithmetic only. I have forgot the problem but I think that the precision part is quite critical for this problem.
Ami ekhono shopno dekhi...
HomePage
Kishwar Shafin
New poster
Posts: 1
Joined: Tue Jul 13, 2010 2:16 pm

Re: 573 The Snail Why WA ?

Post by Kishwar Shafin »

Thnx Jane Alam Jan for your Sample..it really helped...but my code got accepted in ANSI C but it returns time limit exceeded in C++ ...i want to know y?
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 573 The Snail Why WA ?

Post by sohel »

If you post your code, it'd be easier for us to spot the reason. :)
dennywithy
New poster
Posts: 1
Joined: Thu Oct 21, 2010 6:16 pm

Re: 573 The Snail Why WA ?

Post by dennywithy »

why i get wrong output at this test:
50 5 3 14 ->9 (my output)
50 6 4 1 ->89
50 6 3 1 ->19
1 1 1 1 -> 1
?

Code: Select all

#include <stdio.h>
#include <iostream>

using namespace std;
int main() {
    float h,u,d,f;
    do {
       int hari=0;
        scanf("%f %f %f %f",&h, &u, &d, &f);
        if (h>0) {
            float cur =0;
            float after=0; bool stat = true;
            do {
                hari ++;
                if (cur >= h) stat = false;
                after = u + cur;
                cur = after - d;
                if (cur <0) stat = false;
                if (after >h) stat = false;
                u = u - (u * f/100);
                if (u<=0) stat = false;
                //u>=0 && (cur >=0 && cur < h) && after < h)
                
                } while (stat);
                if (u <=0 || cur <0) printf("failure on day %d\n",hari);
                else if (after >= h) printf("succes on day %d\n",hari);
            }
        } while (h!=0);

}
thx :)
Ahmad
New poster
Posts: 16
Joined: Thu Apr 28, 2011 10:48 pm

Re: 573 The Snail Why WA ?

Post by Ahmad »

dennywithy wrote:why i get wrong output at this test:
from the problem statement
(The distance lost to fatigue is always 10% of the first day's climbing distance.)

keep this in mind ;)
Ahmad
New poster
Posts: 16
Joined: Thu Apr 28, 2011 10:48 pm

Re: 573 The Snail Why WA ?

Post by Ahmad »

i have a question guys ... how can i get this 0.000 time ?!
rucczh
New poster
Posts: 1
Joined: Thu Dec 01, 2011 8:09 am

Re: 573 The Snail Why WA ?

Post by rucczh »

There is a tricky!
Pay attention to this.
If you keep reducing the value u, u may be negative, which is obviously wrong!!

try this
56 3 1 5
answer is
failure on day 32
not failure on day 28
NickStern
New poster
Posts: 3
Joined: Wed Nov 20, 2013 1:29 am

Re: 573 The Snail Why WA ?

Post by NickStern »

Hi I was wondering if someone could help me figure out why my code keeps getting WA. It passes all of the test input and the input described in the board here. Thank you in advance.

Code: Select all

import java.util.*;
class Main {
    public static void main (String args[])
    {
        (new Main()).Snail();
        System.exit(0);
    }
    void Snail()
    {
        Scanner scan = new Scanner(System.in);
        double height, distance, drop, fatigue, length;
        int day;
        height = -1;
        while (height != 0)
        {
            height = scan.nextDouble();
            if (height != 0)
            {
                length = 0;
                day = 0;
                distance = scan.nextDouble();
                drop = scan.nextDouble();
                fatigue = (scan.nextDouble() / 100) * distance;
                if (length < height)
                {
                length += distance - drop;
                day++;
                }
                while (length >= 0 && length <= height)
                {
                    if (distance - fatigue > 0)
                    distance -= fatigue;
                    else
                    distance = 0;
                 length += distance;

                  if (length <= height)
                  {
                   length -= drop;

                  }
                    day++;
                }
                if (length < 0)
                {
                  System.out.println("failure on day " + day);
                }
                else
                {
                    System.out.println("success on day " + day);
                }
            }
        }
    }
}
Farsan
New poster
Posts: 34
Joined: Fri Aug 12, 2011 6:37 am

Re: 573 The Snail Why WA ?

Post by Farsan »

Before AC i received a WA because i overlooked the statement "If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day" .
Post Reply

Return to “Volume 5 (500-599)”