BNU 34988 Happy Reversal

Source: Internet
Author: User
Tags cas

Happy Reversalelfness 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
SOURCE2014 ACM-ICPC Beijing Invitational Programming Contest


Puzzle and Code:


#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <    Cstring>using namespace Std;long long b_2[63];void init () {b_2[0]=1;    for (int i=1;i<=60;i++) {b_2[i]=2*b_2[i-1];    }}long long Cal (Char S[],int v) {Long long ans=0;    int Len=strlen (s);    int i=0;    for (int i=0;i<len;i++) if (v==1&&s[i]== ' 1 ') {ans+=b_2[len-i-1];    } else if (v==2&&s[i]== ' 0 ') {ans+=b_2[len-i-1]; } return ans;    struct node{int id; A long long Val;} Sn[20010];bool CMP (node A,node b) {return a.val>b.val;}    int main () {init ();    int cas,n,k;    Char s[64];    Memset (s,0,sizeof (s));    scanf ("%d", &cas);        for (int ca=1;ca<=cas;ca++) {scanf ("%d%d", &n,&k);            for (int i=0;i<n;i++) {scanf ("%s", s);            Sn[i*2].id=sn[i*2+1].id=i;            Sn[i*2].val=cal (s,1);        Sn[i*2+1].val=cal (s,2); } sort (sn,sn+2*n,cmp);        printf ("Case #%d:", CA);            if (n==1) {printf ("0\n");        Continue        } if (sn[0].id!=sn[2*n-1].id) {printf ("%lld\n", sn[0].val-sn[2*n-1].val);        } else {printf ("%lld\n", Max (Sn[0].val-sn[2*n-2].val,sn[1].val-sn[2*n-1].val)); }} return 0;} /* We just need to find out the number of each number itself and its bitwise negation. Since we cannot subtract a number from its bitwise inverse, we numbered two of the same number of origins. Then all the numbers are sorted to find the maximum number and the smallest number, if the two number of different origins, then directly with the large number minus the decimal is the answer, if the two numbers are the same, then we use the second largest number minus the smallest number, and the largest number minus the second small number to compare, the output is larger. */





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.