|
|
вернуться в форумWhy system give me WA1? Послано krey 9 май 2010 00:43 my program variation: #include <stdio.h> #include <math.h> int main() { int nrstones, i, min, w1, w2; int *weights; scanf("%d", &nrstones); weights = new int[nrstones]; for(i = 0; i < nrstones; i++) { scanf("%d", &weights[i]); } min = weights[0]; int perm = 1 << nrstones; for(i = 0; i < perm; i++) { w1 = 0; w2 = 0; int j; for(j = 0; j < nrstones; j++) { if((i >> j) % 2 == 0) w1 += weights[j]; else w2 += weights[j]; } if(min > abs((double)w1 - w2)) { min = abs((double)w1 - w2); if(min == 0) { printf("%d", min); return 0; } } } printf("%d", min); return 0; } |
|
|