H. Happy reversal64-bit integer IO format:
%lldJava class Name:
MainElfness is studying in an operation " not". For a binary number A, if we do operation "Not A"After that, all digits of A would be reversed. (e.g. a=1001101, after Operation "Not A", A'll be0110010). Now elfness have N binary numbers of length K, now he can do operations " not"For some of he numbers. Let's assume after he operations, the maximum number is M, and the minimum number is P. He wants to know what ' s the maximum m-p he can get. Can you help him? Inputthe first line of input was an integer T (t≤60), indicating the number of cases. For each case, the first line contains 2 integers n (1≤n≤10000) and K (1≤k≤60), the next n lines contains N binary Numbers, one number per line and indicating the numbers that elfness have. The length of each binary number is K. Output
For each case, first output of the case number as ' case #x: ', and X is the case number. Then you should output a integer, indicating the maximum result that elfness can get.
Sample Input
25 61001000011000100010100011111115 700011010001011001001101110001001011
Sample Output
Case #1:51Case #2:103
Code:
#include <stdio.h> #include <string.h> #include <limits.h> #define INF 0x7ffffffffffffffflint 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) {f or (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];p rintf ("Case #%d:%lld\n", case++, max-min);} return 0;}