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 ...
随机推荐
- Feature hashing相关 - 1
考虑典型的文本分类,一个经典的方法就是 分词,扫描所有特征,建立特征词典 重新扫描所有特征,利用特征词典将特征映射到特征空间编号 得到特征向量 学习参数 w 存储学习参数 w , 存储特征映射 ...
- LeetCode之Binary Tree Level Order Traversal 层序遍历二叉树
Binary Tree Level Order Traversal 题目描述: Given a binary tree, return the level order traversal of its ...
- jq与js 区别
$(this).html(666); <div id="a">123</div> <script> $("#a").clic ...
- [Eclipse] Eclipse配置Tomcat插件
1 . Eclipse IDE 3.6 for Java EE Developersat- 5.5.28 或者以上版本 : 2 . 安装 Tomcat 插件 , 文件名: tomcatPluginV3 ...
- Effective C++ 之 Item 6 : 若不想使用编译器自动生成的函数,就该明确拒绝
Effective C++ chapter 2. 构造 / 析构 / 赋值运算 (Constructors, Destructors, and Assignment Operators) Item 6 ...
- 在Salesforce中调用外部系统所提供的的Web Service
这里需要提供外部service所对应的WSDL文件(Salesforce只支持从本地上传),并且提供的WSDL文件有如下两点要求: 1):wsdl 文件只能有一个binding,Salesforce是 ...
- windows主机开启openssl的方法
转自:http://www.feichang56.com/openssl/
- Android自动化压力测试之Monkey Test 异常解读(五)
monkey结果分类 monkey结果详细解读 monkey运行log输出后,得读懂日志内容,定位错误 lgo日志顺序输出分别为 测试命令信息.随机事件流(11种事件).异常信息(anr.crash ...
- Popupwindow 的简单实用,(显示在控件下方)
第一步: private PopupWindow mPopupWindow; 第二步:写一个popupwindow的布局文件XML <?xml version="1.0" e ...
- Tomcat不输入项目名进入自己项目(根目录指向自己的项目)
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDepl ...