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

## 不知道哪里出错了，就是叫不上去，请各位帮看看！

Posted by zhangqiang523 at 2009-10-30 18:57:29 on Problem 1339
```#include<iostream>
using namespace std;
int power(int x);
int zuhe(int y,int *a);
int main()
{
int n;
cin>>n;
for(int d=0;d<n;d++)
{
int temp=0;
int m;
int result;
cin>>m;
int *num=new int[m];
for(int j=0;j<m;j++)
cin>>num[j];
/*  for(int k=0;k<m-1;k++)   //不知道该不该有
{
for(int h=k;h<m;h++)
{
if(num[h]>num[h+1])
{
temp=num[h];
num[h]=num[h+1];
num[h+1]=temp;
}
}
}   */
for(int i=1; ;i++)
{
int sum=0;
sum=power(i);
if(sum<m)
continue;
else if(sum==m)
{
int qh=0;
qh=zuhe(m,num);
result=i*qh;
break;
}
else
{
if((i-1)==0)
{
result=i*num[0];
break;
}
int sum1=0;
sum1=power(i-1);
int u=0;
u=m-sum1;
int qh1=0,qh2=0;
qh1=zuhe(2*u,num);
for(int t=2*u;t<m;t++)
qh2+=num[t];
result=i*qh1+(i-1)*qh2;
break;
}
}
cout<<result<<endl;
}
system("pause");
return 0;
}

int power(int x)
{   int mi=1;
for(int k=1;k<=x;k++)
mi*=2;
return mi;
}

int zuhe(int y,int *a)
{
int he=0;
for(int q=0;q<y;q++)
he+=a[q];
return he;
}```

Followed by: