Page 1 of 1

12709 - Falling Ants

Posted: Mon Dec 09, 2013 10:48 pm
by alaminanik
#include <iostream>
using namespace std;
int main()
{
int t,l,w,h,result,temp=0,temp2=0;
while(true)
{
cin>>t;
if(t == 0) break;
while(t--)
{
cin>>l>>w>>h;
if(h>temp)
{
result=l*w*h;
temp2=result;
temp=h;
}
if(h==temp)
{
result=l*w*h;
temp=h;
if(temp2<result)
temp2=result;
}
}
cout<<temp2<<endl;
}
return 0;
}

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Tue Dec 10, 2013 2:43 am
by aliatti
Try these cases:
1
1 2 3
1
1 1 1
0
Answer:
6
1
Yours:
6
6

Got it?
By the way, thanks to your code I could realize my own mistake.

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Tue Dec 10, 2013 4:29 pm
by saju10
why wrong ans..here is my code.....
#include<stdio.h>
int main()
{
int i,textCase,l,w,h;
while(scanf("%d",&textCase)&&textCase)
{
int volume1=0,volumeFinal=0,max=0;;
for(i=1; i<=textCase; i++)
{
scanf("%d%d%d",&l,&w,&h);
if(h>=max)
{
volume1=l*w*h;
if(volumeFinal<volume1)
volumeFinal=volume1;
max=h;
}
}
printf("%d\n",volumeFinal);
}
return 0;
}
Any one help me pls.

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Tue Dec 10, 2013 10:27 pm
by brianfry713
Input:

Code: Select all

2
2 2 1
1 1 2
0
AC output: 2

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Wed Dec 11, 2013 12:39 am
by alaminanik
Thanks aliatti :)
Now, i solved it.

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Wed Dec 11, 2013 8:32 am
by saju10
for(int i=1;;i++)
thank u brianfry713;

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Sat Jan 04, 2014 11:04 pm
by saju10
66

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Thu Jul 24, 2014 4:35 am
by sampad74
Why runtime error ?!!!Please,any one help me to find a bug in my program...here is my code

Code: Select all

got ac

Re: 12709 - Falling Ants [Wrong Answer]

Posted: Thu Jul 24, 2014 2:26 pm
by lighted
First line of each test case contains an integer T (T <= 100) which denotes the total number of ants
to consider.
Increase arrray limit

Code: Select all

int l[51],w[51],h[51],v,t,i;
It must be

Code: Select all

int l[101],w[101],h[101],v,t,i;

Re: 12709 - Falling Ants

Posted: Wed Oct 15, 2014 1:12 am
by AsmaeFILALI
i don't know why im gettin a WA

Code: Select all

import java.util.Scanner;

 class Main {
    public static void main(String [] args)
    {
        Main mc=new Main();
        mc.begin();
    
    }
    void begin()
    {
        Scanner sc =new Scanner(System.in);
        int cases =sc.nextInt();
        int l,w,h,vol=0,mvol=0;
        double f=0,max=0;
        while(cases!=0)
        {   mvol=0;vol=0;
            for(int i=0;i<cases;i++)
            {
                l=sc.nextInt();
                w=sc.nextInt();
                h=sc.nextInt();
                f=h;
                
                if(max<=f)
                {
                    max=f;
                    vol=l*w*h;
                    if(mvol<vol)mvol=vol;
                }
                
            
            }
            System.out.println(mvol);
            cases=sc.nextInt();
        }
        
    }
}
:oops:

Re: 12709 - Falling Ants

Posted: Thu Oct 16, 2014 10:57 pm
by brianfry713
Try solving it without using floating point.

Re: 12709 - Falling Ants

Posted: Sat Oct 18, 2014 6:24 pm
by lighted
Change code to

Code: Select all

while(cases!=0)
{   
    max = mvol = vol = 0;
    ..
            
    f=h;
    vol=l*w*h;

    if(max<f || (max == f  &&  mvol<vol))
    {
        max=f;
        mvol=vol;
    }
}
By the way, why did you made f and max double? (int was enough)

Don't forget to remove your code after getting accepted. 8)