ACM-ICPC 2014 Beijing Invitational H Happy Reverse [simulation]

Source: Internet
Author: User

Test instructions: Given n binary strings, you can invert some of these 0 and 1 (i.e. 0 to 0) to find the difference between the maximum and minimum values in n strings after conversion.


Analysis: The idea is to put all the strings and invert the existence of an array, and then sort, find the difference between the maximum and minimum values, (if the same string is reversed, find the second largest and smallest or second small and largest in the maximum value). Note that if there is only one string, the result is 0.


DEBUG:

It's been inscribed for a long time

1. The first time with vim, very cool, but not yet skilled

2. Ignoring the scope of the problem, it is obvious to use Longlong

3. After using the Longlong also WA, with a script run out of data found in Longlong, Min value to become (1<<63)-1 but can not write, should write a longlong is 1<< 30, and then shift on this longlong basis.


Finally, I have to say that Bnuoj really looks a lot better than POJ.

    #include <iostream> #include <cmath> #include <cstring> #include <cstdio> using NA    Mespace std;    Char str[111111][222];    Long Long tmp=1<<30;    Const Long Long max_long= (tmp<<33)-1;    Long Long num[111111];    Long Long m,n; void Getrev (char* to,char* source,long long len) {for (Long long i=0;i<len;i++) to[i]=source[i]== ' 0 '? '        1 ': ' 0 ';    to[len]= ' + ';        A long long getnum (char* s,long long len) {long long sum=0;            For (long long i=0;i<len;i++) {sum*=2;        sum+=s[i]-' 0 ';    } return sum;        } int main () {Long long test;        cin>>test;            For (long long time=1;time<=test;time++) {cin>>m>>n;            For (long long i=1;i<=m;i++) cin>>str[i];                /*if (m==1) {printf ("Case #%d:0\n", time);            Continue   }*/         For (long long i=m+1;i<=2*m;i++) Getrev (str[i],str[i-m],n);            Long long Minn=max_long;long long maxn=0;            For (long long i=1;i<=2*m;i++) num[i]=getnum (str[i],n);            Long Long Max1=0,max1index,min1=max_long,min1index;            Long Long Max2=0,max2index,min2=max_long,min2index; For (long long i=1;i<=2*m;i++) {if (num[i]>max1) {MA                    X1=num[i];                Max1index=i;                    } if (num[i]<min1) {min1=num[i];                Min1index=i; }} for (Long long i=1;i<=2*m;i++) {if (I!=max1index&&num[i]                    &GT;MAX2) {Max2=num[i];                Max2index=i; } if (i!=min1index&&num[i]<min2) {min2=nUm[i];                Min2index=i;                }} if (ABS (Min1index-max1index)!=m) {maxn=max1;            Minn=min1; } else {if (max1-min2>max2-min1) {//cout<&lt ;"                    1 "<<endl;                maxn=max1;minn=min2;                    } else {//cout<< "2" <<endl;                Maxn=max2;minn=min1;            }}//cout<<maxn<< ' <<minn<<endl;        printf ("Case #%lld:%lld\n", Time,maxn-minn);    } return 0; }


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.