Page 3 of 3

Re: 10014 - Simple Calculations

Posted: Tue Sep 16, 2008 5:45 am
by stcheung
aeiou, consider the following input. Your program returns 34.62 while the answer should be 27.85. By the way, if you want an alternative way to do it, you can consider writing each a in terms of a[1], a[0] and a constant. For instance, you can write a[2] as 2*(a[1]+c[1]) - a[0] and so forth until you can formulate a[n+1] in terms of a[1], a[0] and a constant. Then just solve for a[1].

1

2
50.50
43.45
10.15
10.15

10014 got time limit error

Posted: Fri Oct 12, 2012 12:35 pm
by raihan004
here is my code face time limt error how solve this problem
using this logic?

Code: Select all

#include<stdio.h>
int rec(long n)
{
    if(n%10>0)
    return n%10;
    else if(n==0)
    return 0;
    else rec(n/10);
}
int main()
{
    long p,q;
    long sum=0;
    long i;
    while(scanf("%ld%ld",&p,&q)!=0)
    {
        if(p<0&&q<0)
        break;
        else
        {
            for(i=p;i<=q;i++)
                sum+=rec(i);
        }
        printf("%ld\n",sum);
        sum=0;
    }
    return 0;
}


Re: 10014 got time limit error

Posted: Fri Oct 12, 2012 11:39 pm
by brianfry713
It looks like the wrong problem number. Try to think of a faster method. For example, if you were asked to sum the numbers from 1 to 1000000 would you iterate through them all?

10014 - Simple calculations

Posted: Mon Oct 29, 2012 6:40 am
by shondhi
I can't understand why I got WA? Can anyone please help me. Here is my code:

Code: Select all

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n, test, i;
    double sum;
    double a1, a0, a2;
    double ci[3002];
    while(scanf("%d", &n) == 1)
    {
        cout<<endl;
        sum = 0;
        scanf("%d", &n);
        scanf("%lf", &a0);
        scanf("%lf", &a2);
        for(i = 1; i <= n; i++)
        {
            scanf("%lf", &ci[i]);
        }
        for(i = 1; i <= n; i++)
        {
            sum += ci[i];
        }
        a1 = ((a0 + a2)/2) - sum;
        printf("%0.2lf\n", a1);
    }
return 0;
}
N.B: Code will be removed after AC.

Re: 10014 - Simple calculations

Posted: Tue Oct 30, 2012 12:34 am
by brianfry713