CSU 1784 Internet of Lights and Switches 位运算+思维

1784: Internet of Lights and Switches

  Time Limit: 5 Sec       Memory Limit: 128 Mb       Submitted: 246       Solved: 37    

Description

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 lights and 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 someconsecutive 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

让l,r区间能把当前区间所有等的状态调整到已关状态,那么一定是1,l和1,r两个区间把最初的状态调整到了全关的状态。所以求前缀异或和。枚举每一个合法区间的终点,将其所在前缀异或和的状态抑或初状态,可得其起点应有的状态。如果我们在一开始计算前缀和的时候用哈希记录每种状态对应的开关编号,那么这在这一步可以使用二分搜索计算得出合法的起点数,也就是答案数的一部分。

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
using namespace std;

long long n,m,a,b,pre[300005];
map<long long ,vector<int> > mapp;

int main()
{
    int cas=0;
    while (~scanf("%d%d%d%d",&n,&m,&a,&b))
    {
        cas++;
        long long st=((long long)1<<n)-1;
        mapp.clear();
        mapp[st].push_back(0);
        pre[0]=st;
        for (int i=1; i<=m; i++)
        {
            long long cnt=0;
            for (int j=1; j<=n; j++)
            {
                char ch; cin>>ch;
                if (ch=='1')
                {
                    cnt+=((long long)1<<(j-1));
                }
            }
            pre[i]=pre[i-1]^cnt;
            mapp[pre[i]].push_back(i);
        }
        int ans=0;
        for (int i=a; i<=m; i++)
        {
            long long tmp=st^pre[i];
            if (mapp[tmp].size()==0) continue;
            int pos1=lower_bound(mapp[tmp].begin(),mapp[tmp].end(),i-b)-mapp[tmp].begin();
            int pos2=upper_bound(mapp[tmp].begin(),mapp[tmp].end(),i-a)-mapp[tmp].begin();
            ans+=abs(pos1-pos2);
        }
        cout<<"Case "<<cas<<": "<<ans<<endl;
    }
    return 0;
}
Intelligent Analytics for your Intelligent devices 针对智能设备的数据智能分析 Book Description Break through the hype and learn how to extract actionable intelligence from the flood of IoT data About This Book Make better business decisions and acquire greater control of your IoT infrastructure Learn techniques to solve unique problems associated with IoT and examine and analyze data from your IoT devices Uncover the business potential generated by data from IoT devices and bring down business costs Who This Book Is For This book targets developers, IoT professionals, and those in the field of data science who are trying to solve business problems through IoT devices and would like to analyze IoT data. IoT enthusiasts, managers, and entrepreneurs who would like to make the most of IoT will find this equally useful. A prior knowledge of IoT would be helpful but is not necessary. Some prior programming experience would be useful What You Will Learn Overcome the challenges IoT data brings to analytics Understand the variety of transmission protocols for IoT along with their strengths and weaknesses Learn how data flows from the IoT device to the final data set Develop techniques to wring value from IoT data Apply geospatial analytics to IoT data Use machine learning as a predictive method on IoT data Implement best strategies to get the most from IoT analytics Master the economics of IoT analytics in order to optimize business value In Detail We start with the perplexing task of extracting value from huge amounts of barely intelligible data. The data takes a convoluted route just to be on the servers for analysis, but insights can emerge through visualization and statistical modeling techniques. You will learn to extract value from IoT big data using multiple analytic techniques. Next we review how IoT devices generate data and how the information travels over networks. You’ll get to know strategies to collect and store the data to optimize the potential for analytics, and strategies to handle data quality concerns. Cloud resources are a great match for IoT analytics, so Amazon Web Services, Microsoft Azure, and PTC ThingWorx are reviewed in detail next. Geospatial analytics is then introduced as a way to leverage location information. Combining IoT data with environmental data is also discussed as a way to enhance predictive capability. We’ll also review the economics of IoT analytics and you’ll discover ways to optimize business value. By the end of the book, you’ll know how to handle scale for both data storage and analytics, how Apache Spark can be leveraged to handle scalability, and how R and Python can be used for analytic modeling. Style and approach This book follows a step-by-step, practical approach to combine the power of analytics and IoT and help you get results quickly Contents Chapter 1. Questions Chapter 2. Defining Iot Analytics And Challenges Chapter 3. Iot Devices And Networking Protocols Chapter 4. Iot Analytics For The Cloud Chapter 5. Creating An Aws Cloud Analytics Environment Chapter 6. Collecting All That Data – Strategies And Techniques Chapter 7. Getting To Know Your Data – Exploring Iot Data Chapter 8. Decorating Your Data – Adding External Datasets To Innovate Chapter 9. Communicating With Others – Visualization And Dashboarding Chapter 10. Applying Geospatial Analytics To Iot Data Chapter 11. Data Science For Iot Analytics Chapter 12. Strategies To Organize Data For Analytics Chapter 13. The Economics Of Iot Analytics Chapter 14. Bringing It All Together
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值