12709 - Falling Ants

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

Moderator: Board moderators

Post Reply
alaminanik
New poster
Posts: 2
Joined: Mon Dec 09, 2013 10:40 pm

12709 - Falling Ants

Post 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;
}
aliatti
New poster
Posts: 2
Joined: Tue Jan 25, 2011 4:23 am

Re: 12709 - Falling Ants [Wrong Answer]

Post 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.
saju10
New poster
Posts: 8
Joined: Mon Nov 18, 2013 12:09 am

Re: 12709 - Falling Ants [Wrong Answer]

Post 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.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12709 - Falling Ants [Wrong Answer]

Post by brianfry713 »

Input:

Code: Select all

2
2 2 1
1 1 2
0
AC output: 2
Check input and AC output for thousands of problems on uDebug!
alaminanik
New poster
Posts: 2
Joined: Mon Dec 09, 2013 10:40 pm

Re: 12709 - Falling Ants [Wrong Answer]

Post by alaminanik »

Thanks aliatti :)
Now, i solved it.
saju10
New poster
Posts: 8
Joined: Mon Nov 18, 2013 12:09 am

Re: 12709 - Falling Ants [Wrong Answer]

Post by saju10 »

for(int i=1;;i++)
thank u brianfry713;
saju10
New poster
Posts: 8
Joined: Mon Nov 18, 2013 12:09 am

Re: 12709 - Falling Ants [Wrong Answer]

Post by saju10 »

66
sampad74
New poster
Posts: 29
Joined: Wed Jun 18, 2014 3:57 pm
Location: Bangladesh

Re: 12709 - Falling Ants [Wrong Answer]

Post 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
Last edited by sampad74 on Fri Jul 25, 2014 5:06 am, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 12709 - Falling Ants [Wrong Answer]

Post 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;
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
AsmaeFILALI
New poster
Posts: 2
Joined: Thu Sep 25, 2014 2:47 pm

Re: 12709 - Falling Ants

Post 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:
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12709 - Falling Ants

Post by brianfry713 »

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 12709 - Falling Ants

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Post Reply

Return to “Volume 127 (12700-12799)”