For each case, first output the case number as "Case #x: ", and x is the case number. Then you should output an integer, indicating the maximum result that Elfness can get.
2 5 6 100100 001100 010001 010001 111111 5 7 0001101 0001011 0010011 0111000 1001011
Case #1: 51 Case #2: 103
代码:
#include <stdio.h> #include <string.h> #include <limits.h> #define INF 0x7fffffffffffffffl int n, k; char bin[10005][65]; long long val[50005], cnt; void change(int x, int sign) { long long ret, r; ret = 0; r = 1; if (sign == 1){ for (int i = k - 1; i >= 0; i--){ ret += r*(bin[x][i] - '0'); r = r * 2; } } else { for (int i = k - 1; i >= 0; i--){ if (bin[x][i] == '0') ret += r; r = r * 2; } } val[cnt++] = ret; } int main() { int t, CASE = 1; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &k); cnt = 0; for (int i = 0; i < n; i++){ scanf("%s", bin[i]); change(i, 1); change(i, -1); } long long max, min, s1, s2; max = val[0]; s1 = 0; for (int i = 1; i < 2 * n; i++) if (max < val[i]){ max = val[i]; s1 = i; } if (0 == s1 % 2) s2 = s1 + 1; else s2 = s1 - 1; min = INF; for (int i = 0; i < 2 * n; i++) if (i != s2&&min>val[i]) min = val[i]; printf("Case #%d: %lld\n", CASE++, max - min); } return 0; }
2014北京邀请赛 Happy Reversal,布布扣,bubuko.com
原文地址:http://blog.csdn.net/u012964281/article/details/26487505