The 11th session of Hunan University student Program Design Competition: Internet of Lights and switches (hash+ binary + XOR prefix and)

Source: Internet
Author: User
Tags switches

Internet of Lights and switches

Time limit:1 Sec Memory limit:128 MB
Submit:3 Solved:3
[Submit] [Status] [Web Board]

Description

You is a fan of "Internet of Things" (IoT, IoT ), so you build a nice Internet of Lights and switches in your huge Mansion. Formally, there is n lights and m switches, each switch controls one or more lights, i.e. pressing that s   Witch flips the status of those lights (On->off, Off->on). initially, all the lights is on. Your task is to count the number of ways to turn off, the lights by pressing some consecutive switches . Each switch should is pressed more than once.  There is only one restriction:the number of switches you pressed should be between A and B (inclusive).

Input

There'll is at the most test cases. Each test case is begins with a line containing four integers n, m, A, B (2<=n<=50, 1<=a<=b<=m<=300000). Each of the following m lines contains a, string of length n.the i-th character is 1 if and only if that switch controls The i-th light. The size of the whole input file
does not exceed 8MB.

Output

For each test case, print the case number, and the number of ways to turn off all the lights.

Sample Input
2 4 1 4011011002 4 3 3011011006 3 1 3101001010110101001
Sample Output
Case 1:3case 2:0case 3:2


Test instructions: Now there are m lights, there are n switches (m<=50,n<=300000) now switch with 01 strings, for 1 means the switch can operate the current lamp, now must manipulate the continuous k lamp so that these lights are all closed, a<=k<=b, Q Now how many of these continuous switches meet the conditions?
Problem: Last year Province race unexpectedly has a few detachment A, ORZ, map good difficult to think of ah ~. We save an XOR or prefix and, if the XOR of a paragraph is full 1, then this paragraph is desirable. But how to find it? We assume Xorsum[1,i]^xorsum[1,j] For all 1. So Xor[j+1,i] is eligible, the key is how to find this interval? This is the time to use a hash, map mapping to meet the current XOR prefix and all subscript. With a vector record, and then input, as long as the query I in front of how many subscript the XOR value of 1111111...^xor[1,x], and then you can query the current subscript distance I must be a~b, in this range of the number of subscript is current and I The combination becomes the number of intervals to satisfy the condition, and another case is that the [1,i] interval satisfies the condition, which can be directly + +.
#include <iostream>#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<map>#include<vector>using namespaceStd;typedefLong LongLL;Charstr[ the];Const intINF =999999999; Map<LL,vector<int> >MP;intn,m,a,b; LL Chartoll (Char*str) {LL ans=0; intp =1, Len =strlen (str);  for(inti=len-1; i>=0; i--){        if(str[i]=='1') {ans+=p; } P*=2; }    returnans;}intBinary (LL Val,intID) {Vector<int> VEC =Mp[val]; intDown =0, up = Vec.size ()-1, r=-1, l=INF;  while(down<=Up ) {        intMid = (down+up) >>1; if(id-vec[mid]>=A) {R=mid; down= mid+1; }Elseup = mid-1; } Down=0, up = Vec.size ()-1;  while(down<=Up ) {        intMid = (down+up) >>1; if(id-vec[mid]<=c) {L=mid; up= mid-1; }ElseDown = mid+1; }    //printf ("%d%d\n", l,r);    if(L>r)return 0; returnr-l+1;}intMain () {intt =1;  while(SCANF ("%d%d%d%d", &m,&n,&a,&b)! =EOF)        {mp.clear ();  for(intI=0; i<m;i++) {Str[i]='1'; } Str[m]=' /'; LL k= Chartoll (str), xorsum=0, ans =0;  for(intI=1; i<=n;i++) {scanf ("%s", str); LL x=Chartoll (str); Xorsum^=x; if(xorsum==k&&i>=a&&i<=b) ans++; Ans+=binary (k^xorsum,i);        Mp[xorsum].push_back (i); } printf ("Case %d:%lld\n", t++, ans); }}


The 11th session of Hunan University student Program Design Competition: Internet of Lights and switches (hash+ binary + XOR prefix and)

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.