Binary String Copying
Smiling & Weeping
----第一次见你的时候,
在我的心里已经炸成了烟花,
需要用一生来打扫灰炉。
题目大意不难,就是把每种情况枚举,但是记录每种String需要想办法,简单的set<string>会MLE不可行,unordered_set<string>也不行,这就需要我吗使用类似于hashcode一般,用pair<int,int>的形式来记录每种不同的情况,题目解析在代码里:
1 #include<bits/stdc++.h>
2 using namespace std;
3 int t , n , m;
4 int main()
5 {
6 scanf("%d",&t);
7 while(t--)
8 {
9 scanf("%d%d",&n,&m);
10 vector<int> lf(n+10) , rg(n+10);
11 string s;
12 cin >> s;
13 lf[0] = -1; //当s[0]=='1'的时候赋值-1,s[0]=='0'的时候赋值0,便于区分
14 for(int i = 0; i < n; i++)
15 {
16 if(i > 0) lf[i] = lf[i-1];
17 if(s[i] == '0') lf[i] = i;
18 }
19 rg[n-1] = n; //当s[n-1]=='1'时赋值n-1,s[n-1]=='0'的时候赋值n
20 for(int i = n-1; i >= 0; i--)
21 {
22 if(i < n-1) rg[i] = rg[i+1];
23 if(s[i] == '1') rg[i] = i;
24 }
25 // 如果不区分,这是两种不同的情况,比如:01101001011 , 11101001010就无法区分rg出现错误,lf[0]根本没区别
26 // 如果使用set<string> p必会MLE,ε=(´ο`*)))唉,数据结构好用,但是占用空间太大了
27 set<pair<int , int> > p;
28 while(m--)
29 {
30 int a , b;
31 scanf("%d%d",&a,&b);
32 if(a > b) swap(a,b); //不要问我从哪里得到的教训[○・`Д´・ ○]
33 int ll = rg[a-1] , rr = lf[b-1]; // 计算左端点标记1的历史索引,再求右端点0的历史索引
34 if(ll > rr)
35 {
36 p.insert(make_pair(-1,-1));
37 }
38 else
39 p.insert(make_pair(ll , rr));
40 }
41 cout << p.size() << endl;
42 }
43 return 0;
44 }
文章到此结束,我们下次再见,ヾ( ̄▽ ̄)Bye~Bye~
Binary String Copying的更多相关文章
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- NYOJ之Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose a ...
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- Binary String Matching(kmp+str)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- encode_json 会对给定的Perl的数据结构转换为一个UTF-8 encoded, binary string.
use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' => 'Ken' , 'age' => 1 ...
- perl encode_json 会产生 UTF-8 (binary) string decode_json 需要一个 UTF-8 (binary) string
encode_json $json_text = encode_json $perl_scalar Converts the given Perl data structure to a UTF-8 ...
- NYOJ 5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- [LeetCode] Special Binary String 特殊的二进制字符串
Special binary strings are binary strings with the following two properties: The number of 0's is eq ...
- [Swift]LeetCode761. 特殊的二进制序列 | Special Binary String
Special binary strings are binary strings with the following two properties: The number of 0's is eq ...
- [Swift]LeetCode1016. 子串能表示从 1 到 N 数字的二进制串 | Binary String With Substrings Representing 1 To N
Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return ...
随机推荐
- 【python基础】复杂数据类型-列表类型(增删改查)
1.初识列表(list) 列表由一系列按特定顺序排列的数据元素组成.可以将任何类型数据元素加入列表中,其中的数据元素之间没有任何关系.鉴于列表通常包含多个数据元素,给列表指定一个表示复数的名称是个不错 ...
- ensp 链路聚合
链路聚合(Link Aggregation) 指将多个物理端口汇聚在一起,形成一个逻辑端口,以实现出/入流量吞吐量在各成员端口的负荷分担,链路聚合在增加链路带宽.实现链路传输弹性和工程冗余等方面是 ...
- Python获取token数据的几种方式
import requestsfrom urllib import requestimport re# 一.从响应头中获取token# 登录url = 'http://xxx.nhf.cn/api/b ...
- CKS 考试题整理 (11)-沙箱运行容器gVisor
Context 该 cluster使用 containerd作为CRI运行时.containerd的默认运行时处理程序是runc. containerd已准备好支持额外的运行时处理程序runsc (g ...
- Go应用性能优化的8个最佳实践,快速提升资源利用效率!
作者|Ifedayo Adesiyan 翻译|Seal软件 链接|https://earthly.dev/blog/optimize-golang-for-kubernetes/ 优化服务器负载对于确 ...
- 文本识别分类系统python,基于深度学习的CNN卷积神经网络算法
一.介绍 文本分类系统,使用Python作为主要开发语言,通过TensorFlow搭建CNN卷积神经网络对十余种不同种类的文本数据集进行训练,最后得到一个h5格式的本地模型文件,然后采用Django开 ...
- Transaction rolled back because it has been marked as rollback-only大概问题及解决方法
Transaction rolled back because it has been marked as rollback-only 问题:前几天遇到一个问题,代码没有抛出我想要的带自定义提示消息的 ...
- Bean生命周期的扩展点:Bean Post Processor
摘要:在本篇文章中,我们将深入探讨Spring框架中的重要组件--BeanPostProcessor.首先,我们将了解其设计理念和目标,然后通过实际的例子学习如何基础使用它,如何通过BeanPostP ...
- 高并发场景下,6种解决SimpleDateFormat类的线程安全问题方法
摘要:解决SimpleDateFormat类在高并发场景下的线程安全问题可以有多种方式,这里,就列举几个常用的方式供参考. 本文分享自华为云社区<[高并发]更正SimpleDateFormat类 ...
- maven报错:不再支持源选项 5。请使用 6 或更高版本
问题描述 在执行命令 mvn compile 发生错误 D:\Github_NOTES\JavaWeb_Learning\02Java\JavaWeb\Code\Maven1>mvn clean ...