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. Ext Js【Hello World】 ——4.1 beta 1

    准备:vs+ExtJs4.1Beta1 ExtJS 4.1  xiazai_ https://yunpan.cn/cqv6bdBwtRjAj (提取码:2733) 引用,cs文件,js主入口,zh—c ...

  2. 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)

    1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...

  3. “init terminating in do_boot” Windows10 Rabbit MQ fails to start

    在Windows 10环境下安装rabbitmq-server-3.6.2后,CMD中运行命令:rabbitmq-plugins enable rabbitmq_management 报错: { , ...

  4. Go1.7改善了编译速度并且会生成更快的代码

    Go1.7的开发周期正在接近它的下一个里程碑,Go的提交者Dave Cheney报告了子即将发布的版本中,团队成员在语言工具链上的努力. Cheney称,基于当前的开发状态,Go1.7将会很容易就成为 ...

  5. Mysql常用命令详解

    Mysql安装目录 数据库目录 /var/lib/mysql/ 配置文件 /usr/share/mysql(mysql.server命令及配置文件) 相关命令 /usr/bin(mysqladmin ...

  6. C++中引用(&)的用法和应用实例

    转自:http://www.cnblogs.com/Mr-xu/archive/2012/08/07/2626973.html 对于习惯使用C进行开发的朋友们,在看到c++中出现的&符号,可能 ...

  7. linux文本模式下使用PPPOE拨号ADSL上网的方法

    转自:http://www.myzhenai.com.cn/post/945.html 转载请注明出处:http://www.myzhenai.com/thread-15431-1-1.html ht ...

  8. 第四篇:SOUI资源文件组织

    什么是资源? 现代的软件只要有UI,基本上少不了资源. 资源是什么?资源就是在程序运行时提供固定的数据源的文件. 在MFC当道的时代,资源一般就是位图(Bitmap),图标(Icon),光标(Curs ...

  9. [Unity3D]上海某大型游戏公司的基础面试题

    一个小老乡跟我聊到去上海某大公司的基础面试题,面试结果不尽如人意,但还是分享了下面试的试题,刚刚第一次录制视频,给某人讲课,我感觉讲的还算比较耐心,但发现一些新手入门学习的弊端,可能是很普遍的现象,这 ...

  10. connot resolve symbol R

    出现这个原因大都是layout里的xml文件出错,就不会自动生成R文件