| ||||||||||
| 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 | |||||||||
1700 crossing river这怎么错了,思路,分n=1 n=2 n=3 n>=4 当n>=4时,有两种选法。 测试是对的,提交就是WA,谁能给个测试用例
#include<stdio.h>
int p[1001];
int total=0;
int time(int n ){
int m=n;
if(n==1)
return(total+=p[0]);
else if(n==2)
return(total+=p[1]);
else if(n==3)
return(total+=p[0]+p[1]+p[2]);
else{
if(2*p[1]>=p[0]+p[m-1])
{total+=2*p[0]+p[m-2]+p[m-1];
m=m-2;
time(m);}
else{
total+=p[0]+p[m-1]+2*p[1];
m=m-2;
time(m);} }
return total;
}
int main(){
int n ,i,t,j,temp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&p);
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(p>p[j]){
temp=p;p=p[j];p[j]=temp;}}}
total=0;
printf("%d\n",time(n));
}}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator