Page 1 of 2
12032 - The Monkey and the Oiled Bamboo
Posted: Sun Jun 26, 2011 6:17 pm
by Shafaet_du
Here are some test case for those who are getting wa:
Code: Select all
5
6
1 6 10 14 20 30
10
10 20 30 45 60 75 100 234 4546 45666
3
5 10 15
5
10 20 31 41 51
6
1 2 3 10 20 30
output:
Code: Select all
Case 1: 10
Case 2: 41120
Case 3: 6
Case 4: 12
Case 5: 11
But the judge data should contain more tricky cases. I got wa trying to solve the problem with logic. Than i ran a simple binary search simulating the scenario and got ac easily.
Re: 12032
Posted: Sun Jul 17, 2011 3:58 pm
by Eather
ACCEPTED
Re: 12032
Posted: Mon Jul 18, 2011 9:52 pm
by Eather
Shafaet_du wrote:Here are some test case for those who are getting wa:
Code: Select all
5
6
1 6 10 14 20 30
10
10 20 30 45 60 75 100 234 4546 45666
3
5 10 15
5
10 20 31 41 51
6
1 2 3 10 20 30
output:
Code: Select all
Case 1: 10
Case 2: 41120
Case 3: 6
Case 4: 12
Case 5: 11
this is edited code. Im getting WA. Please help me why my code is not giving correct answer?
Re: 12032
Posted: Mon Aug 08, 2011 1:00 am
by naseef_07cuet
I don't know what is wrong with my code...please anyone help me....
Code: Select all
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long a[100090],i,j,k,t,n;
scanf("%ld",&t);
for(i=0;i<t;i++)
{
scanf("%ld",&n);
for(j=0;j<n;j++)
scanf("%ld",&a[j]);
k=a[0];
for(j=n-2;j>=0;j--)
{
if(a[j+1]-a[j]>k)
k=a[j+1]-a[j];
else if(a[j+1]-a[j]==k)
k++;
}
printf("Case %ld: %ld\n",i+1,k);
}
return 0;
}
/code]
Re: 12032
Posted: Mon Aug 08, 2011 3:59 pm
by crip121
naseef, check your output for following input.
Re: 12032
Posted: Mon Aug 08, 2011 9:12 pm
by naseef_07cuet
My code gives output 3...... I think it is the right one...What is wrong???
Re: 12032
Posted: Tue Aug 09, 2011 2:11 am
by mostafa_angel
I got WA !
can anybody give me some testcase for my weak point...
my code :
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int t , n;
int a , b , k;
scanf("%d", &t);
for(int pp = 0; pp < t ; pp++)
{
k = -1;
a = 0;
scanf("%d",&n);
for(int i = 0 ; i < n ; i++)
{
scanf("%d" , &b);
if(b - a == k)
k++;
else
k = max(k , b - a);
a = b;
}
printf("Case %d: %d\n" , pp +1 , k);
}
return 0;
}
Re: 12032
Posted: Tue Aug 09, 2011 6:48 am
by crip121
oh.. im sorry.. here's the input i intended to post
correct answer would be 4. but your code gives 3.
Re: 12032
Posted: Tue Mar 19, 2013 11:09 pm
by brianfry713
Re: 12032
Posted: Fri Jul 05, 2013 10:19 am
by dcclyde
Anyone want to help me? My code passes all test cases given in this thread and a bunch of others that I wrote myself, but I still get WA.
My strategy is to start from the top of the ladder and move downward, at each stage keeping track of how much strength I need to climb the rest of the ladder.
Code: Select all
#include <iostream>
using namespace std;
int main()
{
int T;
int n;
int* rungs;
int str;
cin >> T;
for (int i = 1; i <= T; i++)
{
cout << "Case " << i << ": ";
cin >> n;
rungs = new int[n+1];
rungs[0] = 0;
for (int j = 0; j <= n-1; j++)
{
cin >> rungs[j+1];
}
str = -1;
for (int jump = n; jump >= 0; jump--)
{
if (rungs[jump+1] - rungs[jump] == str)
str += 1;
else if (rungs[jump+1] - rungs[jump] > str)
str = rungs[jump+1] - rungs[jump];
}
cout << str << endl;
delete [] rungs;
}
return 0;
}
Re: 12032
Posted: Fri Jul 05, 2013 11:15 pm
by brianfry713
Doesn't match the sample I/O.
Re: 12032
Posted: Sat Jul 06, 2013 1:59 am
by dcclyde
brianfry713 wrote:Doesn't match the sample I/O.
It certainly does when I run it, unless there's some formatting mistake that I'm not noticing. Admittedly I'm compiling in visual c++, but I wouldn't expect that to matter here. Which case was wrong when you tried it?
Thanks for taking a look in any case

Re: 12032
Posted: Mon Jul 08, 2013 11:07 pm
by brianfry713
Re: 12032
Posted: Sat Dec 14, 2013 5:28 pm
by reza_cse08
I can not find the error. please help......
/**************************************12032_monkey.cpp**************************************************/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
long int t, n, m, p, l, d, i, a[100000] = {0};
t = 0;
cin>>n;
while(n!=0)
{
t++;
cin>>p;
d = 0;
for(i= 0;i<p;i++)
{
cin>>a;
if(i==0)
{
d = a[0];
}
else if(i>0)
{
if((a - a[i-1])>d)
{
d = a-a[i-1];
}
}
}
m = d;
for(i = 0;i<(p-1);i++)
{
if(a[0]==d)
{
d--;
}
if((a[i+1]-a)==d)
{
d--;
}
else if(d<(a[i+1]-a))
{
m++;
d = m;
i = -1;
}
}
cout<<"Case "<<t<<": "<<m<<endl;
memset(a, 0,sizeof(a));
n--;
}
return 0;
}
Re: 12032
Posted: Tue Dec 17, 2013 10:51 pm
by brianfry713
Move lines 37-40 outside of the for loop:
if(a[0]==d)
{
d--;
}