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. 趣味C++

        用三段 140 字符以内的代码生成一张 1024×1024 的图片 Kyle McCormick 在 StackExchange 上发起了一个叫做TweetableMathematical A ...

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

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

  3. BI 项目管理之角色和职责

          DW/BI 系统在生命周期中需要许多不同的角色和技能,它们来自业务和技术领域.本文将介绍创建DW/BI 系统所涉及的主要角色.角色和人之间很少是一对一关系.与我们合作的团队小到只有一人,大 ...

  4. 攻城狮在路上(壹) Hibernate(三)--- 属性访问、命名策略、派生属性、指定包名等

    一.hibernate访问持久化类属性的策略: 在<property>元素中的access属性用于指定Hibernate访问持久化类属性的方式. 常见的方式如下: 1.property:默 ...

  5. 7-15ALL、 ANY、SOME子查询

    ALL:所有 ANY:部分 SOME:与ANY相同,使用ANY的地方都可以用SOME替换. >ALL:父查询中列的值必须大于子查询返回的值列表的每一个值. >ANY:父查询中的返回值必须大 ...

  6. Linux系统安装及初始化(ubuntu14.04)

    Windows 7下硬盘安装Ubuntu 14.04图文教程 Ubuntu 官方已经发布了正式版的 Ubuntu 14.04 LTS,并宣称这是为云计算准备的版本.该版本在云平台和伸缩环境的可靠性.性 ...

  7. 生成n位随机字符串

    --1.借助newid() Go --创建视图(因为在函数中无法直接使用newid()) create view vnewid as select newid() N'MacoId'; go --创建 ...

  8. minix3(一)安装以及编辑文件

    作为一条通信狗,最近开始自学操作系统.听说用MINIX3学操作系统很好,就决定跟UCSB的课程试试. 首先在虚拟机上安装MINIX3. 开始用的VM Station,按照百度文库里安装minix3的教 ...

  9. 【转】Spark-Sql版本升级对应的新特性汇总

    Spark-Sql版本升级对应的新特性汇总 SparkSQL的前身是Shark.由于Shark自身的不完善,2014年6月1日Reynold Xin宣布:停止对Shark的开发.SparkSQL抛弃原 ...

  10. JVM参数调优

    JVM参数调优 JVM参数调优是一个很头痛的问题,可能和应用有关系,下面是本人一些调优的实践经验,希望对读者能有帮助,环境LinuxAS4,resin2.1.17,JDK6.0,2CPU,4G内存,d ...