Description
You are a fan of "Internet of Things"(IoT, 物联网), so you build a nice Internet of Lights and Switches in your huge mansion. Formally, there are n lights and m switches, each switch controls one or more lights, i.e. pressing that switch flips the status of those lights (on->off, off->on).
Initially, all the lights are on. Your task is to count the number of ways to turn off all the lights by pressing someconsecutive switches. Each switch should not be pressed more than once. There is only one restriction: the number of switches you pressed should be between a and b (inclusive).
Input
There will be at most 20 test cases. Each test case 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 01 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 4 01 10 11 00 2 4 3 3 01 10 11 00 6 3 1 3 101001 010110 101001
Sample Output
Case 1: 3 Case 2: 0 Case 3: 2
Hint
Source
湖南省第十一届大学生计算机程序设计竞赛#include<stdio.h>
#include<string.h>
#include<math.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
char str[80];
const int INF = 999999999;
map<LL,vector<int> > mp;
int n,m,A,B;
LL charToLL(char *str)
{
LL ans = 0;
int p = 1,len = strlen(str);
for(int i=len-1;i>=0;i--)
{
if(str[i]=='1')
{
ans+=p;
}
p*=2;
}
return ans;
}
int binary(LL val,int id)
{
vector <int> vec = mp[val];
int down = 0,up = vec.size()-1,r=-1,l=INF;
while(down<=up)
{
int mid = (down+up)>>1;
if(id-vec[mid]>=A)
{
r = mid;
down = mid+1;
}else up = mid-1;
}
down = 0,up = vec.size()-1;
while(down<=up)
{
int mid = (down+up)>>1;
if(id-vec[mid]<=B)
{
l = mid;
up = mid-1;
}else down = mid+1;
}
//printf("%d %d\n",l,r);
if(l>r) return 0;
return r-l+1;
}
int main()
{
int t = 1;
while(scanf("%d%d%d%d",&m,&n,&A,&B)!=EOF)
{
mp.clear();
for(int i=0;i<m;i++)
{
str[i] = '1';
}
str[m]='\0';
LL k = charToLL(str),xorsum=0,ans = 0;
for(int i=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);
}
}
本文探讨了一道有趣的物联网(IoT)问题:如何通过连续按压一定数量的开关来关闭所有初始状态为开启的灯。文章提供了详细的输入输出样例及解析代码,帮助读者理解并解决这个问题。
1580

被折叠的 条评论
为什么被折叠?



