NBUT 1646 Internet of Lights and Switches

Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format:

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 some consecutive 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
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
#include"map"
using namespace std;
typedef long long LL ;
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define FK(x) cout<<"["<<x<<"]\n"
#define bigfor(T) for(int qq=1;qq<= T ;qq++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 LL light_now[300006]; int main() {
char s[123];
int n,m,a,b;
int qq=1;
LL light_change;
while(~scanf("%d%d%d%d",&n,&m,&a,&b)) {
map< LL , vector<int> > mp; // LL 保存开关的状态,vector 保存 能够按到这个状态的所有起点。
mp.clear();
light_now[0]=0;
mp[0].push_back(0);
for(int i=1; i<=m; i++) {
scanf("%s",s);
// FK(s);
light_change=0;
for(int j=0; j<n; j++) {
if(s[j]=='1')light_change+=(1ll<<j); //按照50位数来保存灯的状态
}
// FK(light_change);
light_now[i]=light_change^light_now[i-1]; //取反,现在开关的状态。
// FK(light_now[i]);
mp[light_now[i]].push_back(i); //把每一个需要被按下的键,能够按到这个状态的所有起点保存。
}
int ans=0;
for(int i=1; i<=m; i++) {
LL t=((~light_now[i])&((1ll<<n)-1)); //需要被按下的键
if(!mp[t].empty()) {
// int x=mp[t].front();
// mp[t].pop();
// if(x>=a&&x<=b)ans++;
int l=lower_bound(mp[t].begin(),mp[t].end(),i-b)-mp[t].begin(); //查找下边界
int r=upper_bound(mp[t].begin(),mp[t].end(),i-a)-mp[t].begin(); //查找上边界
ans+=r-l; //记录所有的可能性。
}
}
printf("Case %d: ",qq++);
printf("%d\n",ans);
}
return 0;
} /*/
2 4 1 4
01
10
11
00
2 4 3 3
01
10
11
00
6 3 1 3
101001
010110
101001 /*/

  

ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector的更多相关文章

  1. 湖南省第十一届大学生程序设计竞赛:Internet of Lights and Switches(HASH+二分+异或前缀和)

    Internet of Lights and Switches Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 3  Solved: 3[Submit][ ...

  2. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  3. ACM: NBUT 1105 多连块拼图 - 水题 - 模拟

    NBUT 1105  多连块拼图 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  4. 牛客网 暑期ACM多校训练营(第二场)J.farm-STL(vector)+二维树状数组区间更新、单点查询 or 大暴力?

    开心.jpg J.farm 先解释一下题意,题意就是一个n*m的矩形区域,每个点代表一个植物,然后不同的植物对应不同的适合的肥料k,如果植物被撒上不适合的肥料就会死掉.然后题目将每个点适合的肥料种类( ...

  5. ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)

    Description We all use cell phone today. And we must be familiar with the intelligent English input ...

  6. ACM学习历程——UVA540 Team Queue(队列,map:Hash)

    Description   Team Queue   Team Queue  Queues and Priority Queues are data structures which are know ...

  7. NBUT [1475] Bachelor

    [1475] Bachelor http://acm.nbut.cn:8081/Problem/view.xhtml?id=1475 时间限制: 1000 ms 内存限制: 65535 K 问题描述 ...

  8. ACM学习大纲

    1 推荐题库 •http://ace.delos.com/usaco/ 美国的OI 题库,如果是刚入门的新手,可以尝试先把它刷通,能够学到几乎全部的基础算法极其优化,全部的题解及标程还有题目翻译可以b ...

  9. ACM训练大纲

    1. 算法总结及推荐题目 1.1 C++ STL • STL容器: set, map, vector, priority_queue, queue, stack, deque, bitset• STL ...

随机推荐

  1. PHP 获取图像信息 getimagesize 函数

    getimagesize() 函数用于获取图像尺寸,类型等信息. imagesx() 函数用于获取图像的宽度. imagesy() 函数用于获取图像的高度. getimagesize() getima ...

  2. JavaWeb学习之Path总结、ServletContext、ServletResponse、ServletRequest(3)

    1.Path总结 1.java项目 1 File file = new File(""); file.getAbsolutePath(); * 使用java命令,输出路径是,当前j ...

  3. Atlas 安装和配置

    前提得配置好主从:http://www.cnblogs.com/super-d2/p/4802990.html 首先,先去下载Altas的rpm包,下载地址:https://github.com/Qi ...

  4. js判断当前的访问是手机还是电脑

    <script type="text/javascript"> //平台.设备和操作系统 var system ={ win : false, mac : false, ...

  5. PHPCMS V9 点击量排行调用方法

    首先调用的标签代码如下: {pc:content action=”sitehits” siteid=”4″ num=”10″ order=”views DESC” cache=”3600″} {loo ...

  6. 智能车学习(十)——MMA8451加速度计的使用

    一.驱动说明: 就是使用I2C的通信方式驱动这款加速度计就行了,代码的话选择使用51单片机的代码进行移植. 二.代码分享: 1.头文件: #ifndef MMA8451_H #define MMA84 ...

  7. java中 几种数据库连接池 的写法

    JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.l ...

  8. 记一次小团队Git实践(下)

    在上篇中,我们已经能基本使用git了,接下来继续更深入的挖掘一下git. 更多的配置自定义信息 除了前面讲的用户名和邮箱的配置,还可以自定义其他配置: # 自定义你喜欢的编辑器,可选 git conf ...

  9. DOM--3 DOM核心和DOM2 HTML(3)

    核心Element对象 操作Element对象的属性 为了简化对attributes的处理,Element对象中包含了很多用来操纵Node对象的attributes属性的方法: getAttribut ...

  10. 破解ZIP加密文件密码fcrackzip

    破解ZIP加密文件密码fcrackzip ZIP是最常见的文件压缩方式.由于其压缩算法开源,主流操作系统都支持这种压缩算法.ZIP压缩方式支持密码加密.加密的时候会在文件头部保存密钥相关信息.利用这个 ...