Page 3 of 4

Posted: Sun Feb 20, 2005 6:52 am
by IIUC GOLD
I didn't find any wrong with this problem.

You have to careful about the intermediate calcualtions. Although the problem description says that the output will fit in 32 bit integer, but the intermediate values may be larger than that. So, use Horner's rule to evaluate the derivative of polynomial . Also, careful about the input processing. I used gets() to take the input and strtok() to separate the coefficients.

Code: Select all


char buf[1000000];

int main()
{
                // declare variables
	while (gets(buf))
	{
		sscanf(buf, "%ld", &x);
		px = 0;
		ppx = 0;
		gets(buf);
		ptr = strtok(buf, " \n");
		while (ptr)
		{
			a = atol(ptr);
			ppx = ppx * x + px;
			px = px * x + a;
			ptr = strtok(NULL, " \n");
		}
		// print ppx
	}
	...
}

Posted: Sun Feb 20, 2005 3:09 pm
by tacolin
To IIUC GOLD:

Thx for your help!! I rewrite my code and got AC! :D

10268

Posted: Mon Mar 28, 2005 5:00 pm
by CodeMaker
Hi I got WA, I used honor's rule and used long long data type....what i can do more? what will be the array limit?

Code: Select all

#include<cstdio>
#include<cstring>
long long a[3000000];
int main()
{
	long long x,sum,i,j,n;
	char temp[3000000],*ptr;

	while(scanf("%lld",&x)==1)
	{
		getchar();
		gets(temp);

		ptr=strtok(temp," ");
		i=0;
		while(ptr)
		{
			sscanf(ptr,"%lld",&a[i++]);
			ptr=strtok(NULL," ");
		}
		i--;
		n=i;
		for(j=0;j<i;j++)
		{
			a[j]*=n--;
		}
		sum=a[0];
		for(j=1;j<i;j++)
		{
			sum=sum*x+a[j];
		}
		printf("%lld\n",sum);
	}
	return 0;
}

Posted: Mon Mar 28, 2005 6:24 pm
by mf
As a matter of fact, you don't need any arrays or whatever in this problem.

A hint: the "definition" of derivative given in the statement is not the best way to proceed. Remember the product rule of differentiation: d(uv) = du v + u dv. Using it and Horner's method you can avoid arrays.

long long was enough in my solution.

10268-WA

Posted: Sun Jun 26, 2005 9:50 am
by lyc
i always got WA. help me plz.

Code: Select all

#include<stdio.h>
#include<math.h>
int main(void)
{
    int i,j,x,l;
    static int c[2000000];
    long long sum;
    char flag;
    while(scanf("%d",&x)!=EOF)
    {
        i=0;
        while(scanf("%d%c",&c[i],&flag)!=EOF)
        {
            if(flag=='\n')break;
            i++;
        }
        sum=0;
        for(j=i;j>0;j--)
            sum+=c[i-j]*j*pow(x,j-1);
        printf("%lli\n",sum);
    }
    return 0;
}

10268 (498') got WA!

Posted: Mon Sep 05, 2005 10:30 am
by liqu
It seems that my program works ok with all the cases i can figure out , but i consistently get WA !
Maybe some good guy can help me with it~

Code: Select all

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>

using namespace std;

int main()
{
    int x;
    char a[1000000],*p;
    int num[1000],i,n,j;
    while(scanf("%d\n",&x)==1)
    {
        long total = 0;
        gets(a);
        p = strtok(a," ");
        num[0] = atoi(p);
        for(p=strtok(NULL," "),i=1; p!=0; p=strtok(NULL," "),i++)
                num[i] = atoi(p);
        
        for(j=0;j<i;j++)
                num[j] *= i-j-1;
        
                for(j=0;j<i-1;j++)
                         total += num[j] * static_cast<long>(pow((double)x,(double)i-j-2)); 
                printf("%ld\n",total);                 
      }    
        
}

10268 - WA :(

Posted: Sun Nov 13, 2005 9:00 pm
by Vladislav Andrushkevich
It seems that my program works ok with all the cases i can figure out , but i consistently get WA !
Can anyone help me please!

program P10268;
var A,X,C,j:integer;
S:string;
Sum:LongInt;
begin
while not EOF do
begin
ReadLn(X);
Read(S);
j:=0;
Sum:=0;
for C:=0 to Length(S) do
if S[C]=' ' then j:=j+1;
while j>0 do
begin
if POS(' ',S)>0 then
begin
VAL(COPY(S,1,POS(' ',S)-1),A,C);
DELETE(S,1,POS(' ',S));
Sum:=Sum+A*j*Round(Exp((j-1)*Ln(X)));
end;
j:=j-1;
end;
WriteLn(Sum);
end;
end.

10268 - 498'

Posted: Mon Dec 12, 2005 7:00 pm
by helloneo
I got RTE.. but I don't see why..~!
Somebody please tell me why.. ~

Code: Select all

CUT AFTER AC
Thanks.. :-)

Posted: Sat Dec 17, 2005 2:19 am
by Jan
Use buf size 1000001 and coef size 400000. I think these are the reasons for which you are getting RTE.

Hope it helps.

int & long long

Posted: Thu Aug 16, 2007 2:34 am
by handsomepot
I use int and got AC
But long long results in WA.
Who can explain why?

wrong answer

Posted: Wed Mar 26, 2008 9:00 pm
by Mata
hi, I try this problem, but it I get wrong answer, i use the same in the 498 and got Ac in that, what could be wrong with this

Code: Select all

#include <iostream>
#include <cmath>
int main()
{
	double cof[200000], xval=0.0, r=0.0;
	int x=0, a=0, k=0;
	char ca=' ';
	while(true)
	{
		x=0, r=0, a=0, k=0;
		scanf("%lf%c",&xval,&ca);
		while((k=scanf("%lf%c",&cof[x],&ca))>=1)
		{
			x++;
			if(ca=='\n')
				break;
		}
		while(a<x)
		{
			if(x-(a+2)>=0)
			{
				r+=cof[a]*(x-(a+1))*pow(xval,x-(a+2));
			}
			a++;
		}
		printf("%.0lf\n",r);
		if(k!=2)
			return 0;
	}
	return 0;
}
If you have some sample input please post it, thanks.

Posted: Thu Mar 27, 2008 5:56 pm
by Jan
Check the cases.

Input:

Code: Select all

1
1073741824 -1073741824 0
1
2147483647 -2147483647 0
2
-1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1
2
-1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-2
-1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-1
1 1 1
Output:

Code: Select all

1073741824
2147483647
-65244729
-2147483647
1155763769
-1
Your code prints an extra 0 at the end of output. May be your input taking part is not fully correct.

stil wa

Posted: Thu Mar 27, 2008 6:28 pm
by Mata
Hi, thanks for the test cases, I try them and i got the same output as you, i didn't find the extra 0 at the end of my output.

Code: Select all

1073741824
2147483647
-65244729
-2147483647
1155763769
-1

Re: 10268 - 498'

Posted: Sat Dec 20, 2008 7:42 am
by deadangelx
test cases

Code: Select all

100000000000000
1
answer

Code: Select all

0

Re: 10268 - 498'

Posted: Mon Mar 16, 2009 8:18 am
by Obaida
I did something wrong?
Some one please figure my mistake. Why this gives me wa? :cry:

Code: Select all

#include<math.h>
long long int a[10000001];
int main()
{
	long long int sum,x,i,j,t;
	char c;
	while(scanf("%lld",&x)==1)
	{
		i=0;
		while(1)
		{
         scanf("%lld%c",&a[i++],&c);
         if(c==10)break;
      }
      sum=0;t=0;
      for(j=i-2;j>=0;j--)
      {
         sum += (j+1)*a[t++]*pow(x,j);
      }
      printf("%lld\n",sum);
   }
   return 0;
}