I tried to submit my source code of the problem 10300 - Ecological Premium and i got the messenge Time limit exceeded. The run time was 3.00 seconds but the Time limited is 1.00 second, i`ve tried to simplify the algorithm but i failed. I don`t know what i can do. pls Help me.
Source Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int n, f, i, j, sum, space, animals, C;
while (n!=EOF){
scanf ("%d", &n);
for( i=0; i<n; i++){
scanf("%d", &f);
sum=0;
for (j=0; j<f; j++){
scanf("%d%d%d", &space, &animals, &C);
sum+=space*C;
}
printf("%d\n", sum);
}
}
return 0;
}
10300 - Ecological Premium
Moderator: Board moderators
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: Time limit exceeded
Several things to note:
Post title should contain Problem no like(10300-ecological premium) not TLE,WA,CE etc.
so remember this.And dont forget to place your code inside Quote tag;
You have problem in input taking. you program continue taking input,never ends.so TLE occurs.
So take input such a way-Code: Select all
int ncase; //variable contain no. of cases; scanf("%d",&ncase); while(ncase>0) { code................. ncase--; }
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
-
- New poster
- Posts: 1
- Joined: Tue Nov 16, 2010 5:32 am
Re: 10300 - Ecological Premium
Use
int main()
{
.....
return 0;
}
instead of void main(void)
Online Judge don't support void main()
int main()
{
.....
return 0;
}
instead of void main(void)
Online Judge don't support void main()
10300 ecological premium
i can't find where is the problem . ![:(](./images/smilies/icon_frown.gif)
plz help me.
here is my code:
![:(](./images/smilies/icon_frown.gif)
plz help me.
here is my code:
#include<stdio.h>
int main()
{
unsigned long int size,animal,env,total,n,f;
scanf("%li",&n);
for(int i=1;i<=n;i++)
{
while(scanf("%li",&f)!=EOF)
{total=0;
for(int j=1;j<=f;j++)
{
scanf("%li%li%li",&size,&animal,&env);
total=size*env+total;
}
printf("%li",total);
}
}
return 0;
}
-
- New poster
- Posts: 2
- Joined: Tue Aug 09, 2011 7:19 pm
10300 - Ecological Premium
I can't find why I am getting wrong answer...plz help me
(I used C-language)
#include<stdio.h>
int main()
{
unsigned long int a,b,c,i,j,testcase,ans=0,farmer,sum;
scanf("%lu",&testcase);
for (i=0;i<testcase;i++)
{
scanf("%lu",&farmer);
for (j=0;j<farmer;j++)
{
scanf("%lu",&a);
scanf("%lu",&b);
scanf("%lu",&c);
sum=a*c;
ans=ans+sum;
}
printf("%lu",ans);
ans=0;
if(j<farmer-1)
printf("\n");
}return 0;
}
![:(](./images/smilies/icon_frown.gif)
(I used C-language)
#include<stdio.h>
int main()
{
unsigned long int a,b,c,i,j,testcase,ans=0,farmer,sum;
scanf("%lu",&testcase);
for (i=0;i<testcase;i++)
{
scanf("%lu",&farmer);
for (j=0;j<farmer;j++)
{
scanf("%lu",&a);
scanf("%lu",&b);
scanf("%lu",&c);
sum=a*c;
ans=ans+sum;
}
printf("%lu",ans);
ans=0;
if(j<farmer-1)
printf("\n");
}return 0;
}
-
- New poster
- Posts: 1
- Joined: Fri Nov 25, 2011 7:08 pm
Re: 10300 ecological premium
you need not to check
As per the problem description your "n" will determine how much test cases are going to give. The code can be written in the following way:
Happy Coding!
Code: Select all
while(scanf("%li",&f)!=EOF)
Code: Select all
long long int size,animal,env,total,n,f;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&f);
total=0;
for(int j=1;j<=f;j++)
{
scanf("%lld%lld%lld",&size,&animal,&env);
total=size*env+total;
}
printf("%lld\n",total);
}
-
- New poster
- Posts: 4
- Joined: Wed Nov 13, 2013 8:47 pm
Re: 10300 ecological premium
AC,thanks
Last edited by luijhy_9234 on Thu Apr 03, 2014 12:47 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10300 ecological premium
print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!