ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector
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
Output
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的更多相关文章
- 湖南省第十一届大学生程序设计竞赛:Internet of Lights and Switches(HASH+二分+异或前缀和)
Internet of Lights and Switches Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 3 Solved: 3[Submit][ ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1105 多连块拼图 - 水题 - 模拟
NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- 牛客网 暑期ACM多校训练营(第二场)J.farm-STL(vector)+二维树状数组区间更新、单点查询 or 大暴力?
开心.jpg J.farm 先解释一下题意,题意就是一个n*m的矩形区域,每个点代表一个植物,然后不同的植物对应不同的适合的肥料k,如果植物被撒上不适合的肥料就会死掉.然后题目将每个点适合的肥料种类( ...
- ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)
Description We all use cell phone today. And we must be familiar with the intelligent English input ...
- ACM学习历程——UVA540 Team Queue(队列,map:Hash)
Description Team Queue Team Queue Queues and Priority Queues are data structures which are know ...
- NBUT [1475] Bachelor
[1475] Bachelor http://acm.nbut.cn:8081/Problem/view.xhtml?id=1475 时间限制: 1000 ms 内存限制: 65535 K 问题描述 ...
- ACM学习大纲
1 推荐题库 •http://ace.delos.com/usaco/ 美国的OI 题库,如果是刚入门的新手,可以尝试先把它刷通,能够学到几乎全部的基础算法极其优化,全部的题解及标程还有题目翻译可以b ...
- ACM训练大纲
1. 算法总结及推荐题目 1.1 C++ STL • STL容器: set, map, vector, priority_queue, queue, stack, deque, bitset• STL ...
随机推荐
- Android 下拉刷新
以前旧版用的是开源的PullToRefresh第三方库,该库现在已经不再维护了: chrisbanes/Android-PullToRefreshhttps://github.com/chrisban ...
- Linux(CentOS)常用操作指令(一)
基本指令集合 1.查看CentOS版本信息 cat /proc/version cat /etc/redhat-release 2.查看安全日志文件信息 tail -f /var/log/secure ...
- Newtonsoft.Json(Json.Net)学习笔记-高级使用(转)
1.忽略某些属性 2.默认值的处理 3.空值的处理 4.支持非公共成员 5.日期处理 6.自定义序列化的字段名称 7.动态决定属性是否序列化 8.枚举值的自定义格式化问题 9.自定义类型转换 10.全 ...
- djcelery的细节篇
http://blog.csdn.net/samed/article/details/50598371 随时撸一撸,要点记心间.. 1. 下面讲解一下celery.py文件的配置内容,为何要这么配置. ...
- scala的tcp通信
client: object ActorClient extends App { import actors.Actor, actors.remote.Node, actors.remote.Remo ...
- JqueryEasyUI 解决IE下datagrid无法刷新的问题 分类: JavaScript JqueryEasyUI 2014-09-20 10:05 510人阅读 评论(1) 收藏
问题描述: 在使用JqueryEasyUI 时,发现在IE下$('#table').datagrid('reload');无效,数据并没有被刷新,究其原因,是因为刷新时,datagrid请求的url没 ...
- JavaScript - 事件流
事件流 事件冒泡就是事件沿DOM树向上传播,在没一级节点上都会发生,直至传播到document对象. 事件捕获正好相反,但是老版本的浏览器不支持,因此很少有人使用事件捕获. 事件处理程序 HTMl 事 ...
- hdu 2232 矩阵 ***
一天四个不同的机器人a.b.c和d在一张跳舞毯上跳舞,这是一张特殊的跳舞毯,他由4个正方形毯子组成一个大的正方形毯子,一开始四个机器人分别站在4 块毯子上,舞蹈的每一步机器人可以往临近(两个毯子拥有同 ...
- Ubuntu下安装Nginx
转载自:http://www.cnblogs.com/skynet/p/4146083.html 1.Nginx安装 我使用的环境是64位 Ubuntu 14.04, Nginx是Nginx 1.10 ...
- OpenMesh 读写网格控制(读取写入纹理坐标,法向等)
OpenMesh读取网格默认是不自动读取obj网格中的法向,纹理坐标等信息的,写入网格同样也是.所以要读取(或写入)这些信息需要修改默认的选项. 先看一下其读写网格的函数 template<cl ...