Page 3 of 4
Re: 573 The Snail Why WA ?
Posted: Wed Apr 30, 2014 8:26 am
by jddantes
Hello, I keep on getting WA. I've tried all the input in this thread
Code: Select all
#include <stdio.h>
int main(){
while(1){
int h,u,d,f;
scanf("%d %d %d %d",&h,&u,&d,&f);
if(!h)
return 0;
f*=u;
h*=100;
u*=100;
d*=100;
int day = 0;
int good = 0;
int pos = 0;
while(1){
day++;
if(u<0)
u = 0;
pos += u;
if(pos>h){
good = 1;
break;
}
u-=f;
pos-=d;
if(pos < 0)
break;
}
if(good)
printf("sucess ");
else
printf("failure ");
printf("on day %d\n",day);
}
return 0;
}
Re: 573 The Snail Why WA ?
Posted: Thu May 01, 2014 12:03 am
by brianfry713
success not sucess
Re: 573 - The Snail
Posted: Wed Aug 20, 2014 1:02 pm
by mratan16
Hi a friend asked me to check his code and was wondering why it was wrong. I tried but could not find fault in it. Can you guys help?
Code: Select all
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double h, u, d, f;
cin >> h >> u >> d >> f;
if ((h == 0) || !(1 <= h <= 100) || !(1 <= u <= 100) || !(1 <= d <= 100) || !(1 <= f <= 100)){
return 0;
}
/* h is where it starts, u is how much it moves, d is the constant it slides down,
and f is the percentage that u is reduced by the next day */
double i, s; // i is the day, s is the snail's current height which is 0
i = 0;
s = 0;
while (true){
i ++; // dawn of the first day which will then keep going
s += u; // adding to the height
if (s > h){
cout << "success on day " << i << endl;
return 0;
}
s -= d; // it is now night, snail slides down
if (s < 0){
cout << "failure on day " << i << endl;
return 0;
}
u -= u * (f/100); // fatigue
cout << s << "," << h << "," << i << endl;
}
}
Thank you very much! .
Re: 573 - The Snail
Posted: Wed Aug 20, 2014 4:56 pm
by lighted
Doesn't match sample I/O.
Re: 573 - The Snail
Posted: Thu Aug 21, 2014 12:11 pm
by mratan16
Thanks again lighted. But I was wondering why?
Re: 573 - The Snail
Posted: Thu Aug 21, 2014 8:16 pm
by brianfry713
The input file contains one or more test cases
Your code is only reading one test case and is printing extra stuff.
Re: 573 - The Snail
Posted: Fri Aug 22, 2014 12:47 am
by mratan16
Thanks a lot but would you know why it also fails on test cases?
Re: 573 - The Snail
Posted: Tue Aug 26, 2014 7:48 pm
by brianfry713
If you know a test case that the code fails on, and you know what the output should be, then look at your code step by step and figure out where it is wrong.
Re: 573 - The Snail
Posted: Sat Dec 20, 2014 10:58 pm
by gautamzero
WA ???
Re: 573 - The Snail
Posted: Sun Dec 21, 2014 9:34 am
by lighted
Input
Code: Select all
1 100 100 100
100 1 100 100
100 1 100 1
0 0 0 0
Acc Output
Code: Select all
success on day 1
failure on day 1
failure on day 1
Re: 573 - The Snail
Posted: Sun Dec 21, 2014 9:40 am
by gautamzero
what a silly mistake!!
thnx lighted

Re: 573 - The Snail
Posted: Sat Jan 23, 2016 1:47 am
by juan321
I have problems with some cases Help D:
success on day 4
failure on day 3
failure on day 7
failure on day 68
success on day 21
failure on day 1
Re: 573 - The Snail
Posted: Fri Jan 29, 2016 6:36 pm
by Zyaad Jaunnoo
juan321 wrote:I have problems with some cases Help D:
success on day 4
failure on day 3
failure on day 7
failure on day 68
success on day 21
failure on day 1
Hello Juan,
Can you please post your code?
Re: 573 - The Snail
Posted: Wed Feb 17, 2016 11:29 am
by Kinleyperker
Can anyone help me with this code...It's getting WA
#include<stdio.h>
int main()
{
int H=1, U, D, F, x;
float s, v, w;
while(H>0)
{
scanf("%d %d %d %d", &H, &U, &D, &F);
w = U*F;
if(H>0)
{
s = 0.00;
for(x=0; ; x++)
{
if(x) v = v - (w/100);
else if(!x) v = U;
s = s + v;
if(s>H)
{
printf("success on day %d\n", x+1);
break;
}
s = s - D;
if(s<0)
{
printf("failure on day %d\n", x+1);
break;
}
}
}
}
return 0;
}

Re: 573 - The Snail
Posted: Sat Mar 19, 2016 12:28 am
by prakashn27
Hi can anyone help me with this code. I am getting wrong answer for a test case. Problem:
573 - The Snail
Code: Select all
int main() {
int h, u, d, f;
cin >> h;
while(h != 0) {
cin >> u >> d >> f;
//cout << "inputs are " << h << u << d << f << endl;
float initial_ht = 0.0, dist_climbed = (float)u, height_after_climbing = 0.0, height_after_sliding = 0.0;
float depeciation_each_day = (float)u * f / 100;
//cout << "depre each day " << depeciation_each_day << endl;
int i = 1;
bool is_success = true;
for(i = 1; height_after_sliding < h; i++) {
initial_ht = height_after_sliding;
cout << initial_ht ;
if(i != 1) {
dist_climbed -= depeciation_each_day;
}
height_after_climbing = initial_ht + dist_climbed;
if (height_after_climbing > h) {
break;
}
if(height_after_climbing < 0) {
is_success = false;
break;
}
height_after_sliding = height_after_climbing - (float)d;
initial_ht = height_after_sliding;
cout << " " << dist_climbed << " " << height_after_climbing << " " << height_after_sliding << endl;
}
if(!is_success) {
cout << "failure on day ";
} else {
cout << "success on day ";
}
cout << i << endl;
cin >> h;
}
}
Input:
Expected output:
Output i get is:
Thanks a lot in advance.