10014 - Simple calculations

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

Moderator: Board moderators

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 10014 - Simple Calculations

Post by stcheung » Tue Sep 16, 2008 5:45 am

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

raihan004
New poster
Posts: 2
Joined: Tue Oct 09, 2012 2:07 am

10014 got time limit error

Post by raihan004 » Fri Oct 12, 2012 12:35 pm

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;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10014 got time limit error

Post by brianfry713 » Fri Oct 12, 2012 11:39 pm

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?
Check input and AC output for thousands of problems on uDebug!

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

10014 - Simple calculations

Post by shondhi » Mon Oct 29, 2012 6:40 am

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.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10014 - Simple calculations

Post by brianfry713 » Tue Oct 30, 2012 12:34 am

Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 100 (10000-10099)”