【HDOJ】2103 Family planning
题目挺有意思。虽然不是很难。
1 #include <stdio.h> 2 3 int main() { 4 unsigned int m, n, case_n; 5 unsigned int i, j, k, tmp, one=1; 6 7 scanf("%u", &case_n); 8 9 while (case_n--) { 10 scanf("%u %u", &m, &n); 11 k = j = 0; 12 for (i=1; i<=n; ++i) { 13 scanf("%u", &tmp); 14 if (tmp && !j) 15 j = i; 16 } 17 if ( (m==n) && (j==0 || j==n) ) { 18 printf("0 RMB\n"); 19 continue; 20 } 21 if (j && j<n) 22 tmp = (one<<(n-j))-1; 23 else 24 tmp = 0; 25 if (m<n) 26 k = (one<<(n-m))-1; 27 else 28 k = 0; 29 tmp = (tmp>k) ? tmp:k; 30 if (tmp) 31 printf("%u0000 RMB\n", tmp); 32 else 33 printf("0 RMB\n"); 34 } 35 36 return 0; 37 }