| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我的程序有什么错?#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int t,m,a,b,ans,k[10000];
long long left[10000],right[10000],num,adder,best;
scanf("%d",&t);
while (t--)
{
scanf("%d%d%d",&m,&a,&b);
for(int i=0;i<m;i++)
scanf("%d",&k[i]);
left[0]=0;num=k[0];adder=0;
for (int i=1;i<m;i++)
{
left[i]=left[i-1]+num*a+adder;
adder+=num;num+=k[i];
}
right[m-1]=0;num=k[m-1];adder=0;
for (int i=m-2;i>=0;i--)
{
right[i]=right[i+1]+num*b+adder;
adder+=num;num+=k[i];
}
best=1000000000;best=best*best;
for (int i=0;i<m;i++)
if (left[i]+right[i]<best)
{
best=left[i]+right[i];ans=i;
}
printf("%d\n",ans+1);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator