|
|
back to boardcan anyone tell me what's wrong with this #include<stdio.h> #include<algorithm> using namespace std; int pile[22];//initial array size int pile_cmp(const void*a,const void *b) { return *(int*)a-*(int*)b; } int main() { int num; scanf("%d",&num); int sum=0; for(int i=0;i<num;i++){ scanf("%d",&(pile[i])); sum+=pile[i]; } if(sum==0)printf("0\n"); else{ qsort(pile,num,sizeof(int),pile_cmp); int ptr=num-1,min=2000000,min_p,tmp; while( ptr>=0 && sum ){ while(ptr>=0 && (sum-(pile[ptr]<<1))<0)ptr--; if(ptr<0)ptr++; tmp=pile[ptr]<<1; if(abs(sum-tmp)<min){ sum=abs(sum-tmp); min=sum; } ptr--; } printf("%d\n",min); } return 0; } before i submit this ,i submit another one ,which got AC but produce different answer with this one;however this one also got AC I wasn't quite clear about what is the correct algorithm for this problem Edited by author 02.08.2011 00:58 Edited by author 02.08.2011 01:05 |
|
|