Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位帮我看看,是哪里出了问题.

Posted by Bupt_Pig at 2006-03-02 12:17:21 on Problem 1701
/*
**1701pkuacm.
*/

#include <stdio.h>
#include <stdlib.h>


main()
{
    long min=99999999,s,num;
    int final,i,time,a,b,m;
    int *k;
    long *up,*down;

    scanf("%d",&time);
    while(time--)
    {
        scanf("%d%d%d",&m,&a,&b);
        k=(int*)malloc(sizeof(int)*(m+1));
        up=(long*)malloc(sizeof(long)*(m+1));
        down=(long*)malloc(sizeof(long)*(m+1));

        for(i=1;i<=m;i++)
        	scanf("%d",&k[i]);

    	s=num=up[m]=0;
    	for(i=m-1;i>=1;i--)
    	{
    	    s=s+num+a*k[i+1];
    	    up[i]=up[i+1]+s;
    	    num=num+k[i+1];
    	}
     	s=num=down[1]=0;
      	for(i=2;i<=m;i++)
       	{
            s=s+num+b*k[i-1];
            down[i]=down[i-1]+s;
            num=num+k[i-1];
        }

        for(i=1;i<=m;i++)
        {
            if(up[i]+down[i]<min)
            {
                min=up[i]+down[i];
               	final=i;
            }
        }

        printf("%d\n",final);
        free(k);
        free(up);
        free(down);

    }
    
     
}                 
                    
        

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator