Crazy Binary String】的更多相关文章

Crazy Binary String 最长01个数相等的子串和子序列 字串用二分做的,有hack数据 :8 00111100 好像数据太水,直接放过去了 下面为二分代码 #include<bits/stdc++.h> using namespace std; int t,n; typedef long long ll; #define P pair<ll,ll> #define fi first #define se second P A[]; ll mx,my; bool cm…
Crazy Binary String 思维 题意 给出01串,给出定义:一个串里面0和1的个数相同,求 满足定义的最长子序列和子串 分析 子序列好求,就是0 1个数,字串需要思考一下.实在没有思路可以看看数组范围(n<=1e5),很像nlogn或者n的算法,这个时候就要考虑一下二分和前缀和优化,二分感觉⑧太行,这个时候研究一下前缀和的性质,发现0 为-1,1为1的时候,前缀和相同的两个位置中间恰好可以构成一个满足定义的串,所以这题就解决了.没有思路的时候多发散一下思维,从多角度思考一下问题.…
题目链接:https://ac.nowcoder.com/acm/contest/883/B 题目大意   给定一个长度为 N 的 01 字符串,输出最长子串和子序列的长度,满足其中 0 和 1 的个数相等. 分析1(DP) 子序列就不说了,谁都会求. 这个 DP 是我自己想的,严格来说复杂度是 O(n2),然而数据比较松,就过了,速度居然很快,主要注释都写代码里了. 代码如下 #include <bits/stdc++.h> using namespace std; #define INIT…
题目传送门 大致题意: 输入整数n(1<=n<=100000),再输入由n个0或1组成的字符串,求该字符串中满足1和0个数相等的最长子串.子序列. sample input: 801001001 sample output: 4 6 题解: 补充一下子串和子序列的区别:字串必须连续,子序列不必连续. 求01个数相等的最长子序列长度:min(0的个数,1的个数). 下面说求01个数相等的最长子串长度: 可以建一个sum数组求前缀和,因为要使0和1个数相等,所以0可以用-1代替,故当sum[r]-…
示例: 输入: 801001001 输出:4 6 题意:一段长度为n且只有 ‘0’ 和 ‘1’ 的字符串,求子串中 ‘0’ 和 ‘1’ 数目相等和子序列中 ‘0’ 和 ‘1’ 数目相等的最大长度. 思路:子序列的最大长度为 ‘0’ 和 ‘1’ 的个数中最小的两倍: 求字串的最大长度就用前缀和,将 ‘1’ 的价值设为1,‘0’ 的价值设为-1,用数组book[i]记录从 0 到 i 的前缀和,再用数组mapp[i]记录前缀和为 i 时的位置,只有当book[j] == book[i] (j > i…
题意: 如题. 或者用我的数组分治也可以,就是有点愚蠢. //#include <bits/stdc++.h> #include <map> #include <iostream> #include <algorithm> /* 在O(n)中找连续的子串 -> 统计前缀和 map记录下标 */ using namespace std; ]; int n; , one = ; ]; map<int, int> mp1, mp2; int ma…
#include<cstdio> #include<iostream> #include<map> using namespace std; map<int,int>k; int max(int x,int y){ if(x>=y){ return x; }else{ return y; } } int min(int x,int y){ if(x>=y){ return y; }return x; } int main(){ ,b=; int…
Crazy Binary String 题目传送门 解题思路 把1记为1,把0记为-1,然后求前缀和,前缀和相等的就说明中间的01数一样.只要记录前缀和数值出现的位置即可更新出答案. 代码如下 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; const int N = 100005; int l[N << 1]; int sum[N]; int ma…
问题 B: Binary String Matching 时间限制: 3 Sec  内存限制: 128 MB提交: 4  解决: 2[提交][状态][讨论版] 题目描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述     Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘10011…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110…
use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' => 'Ken' , 'age' => 19 }, { 'name' => '测试' , 'age' => 25 } ]; print encode_utf8("'name' => '测试'"); print "\n"; my $json_out = encode_json ( $data )…
encode_json $json_text = encode_json $perl_scalar Converts the given Perl data structure to a UTF-8 encoded, binary string. This function call is functionally identical to: $json_text = JSON->new->utf8->encode($perl_scalar) 转换给定的perl数据结构到一个UTF-8编…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110…
Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Every prefix of the binary string has at least as many 1's as 0's. Given a special string S, a move consists of choosing two…
Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Every prefix of the binary string has at least as many 1's as 0's. Given a special string S, a move consists of choosing two…
Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return true if and only if for every integer X from 1 to N, the binary representation of X is a substring of S. Example 1: Input: S = "0110", N = 3 Outp…
https://leetcode.com/problems/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 true if and only if for every integer X from 1 to N, the binary repre…
E - Vasya and Binary String 思路:区间dp + 记忆化搜索 转移方程看上一篇博客. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define y1 y11 #define pi acos(-1.0)…
Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Every prefix of the binary string has at least as many 1's as 0's. Given a special string S, a move consists of choosing two…
How to convert a byte to its binary string representation For example, the bits in a byte B are 10000010, how can I assign the bits to the string strliterally, that is, str = "10000010". ; String s1 = String.format('); System. ; String s2 = Stri…
E. Vasya and Binary String 链接 分析: 对于长度为x的一段序列,我们可以dp出消除的过程的最优方案,背包即可. 然后区间dp,可以先合并完所有的点,即没相同的一段区间合并为一个点.设f[i][j][k]表示消完区间[i,j]和这段区间后面k个元素最大值,其中k个元素的颜色与点j的颜色相同. 转移:可以首先将j和后面k个元素消除,然后消除[i,j-1].也可以枚举一个和j颜色相同的点m,然后分别先消除[m+1,r-1],剩下的区间就和后面k个连在一起了,再求出这段区间的…
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这个字符串与目标串之间不同的字符的个数.要在15次的提问内,找到目标串中任意一个1和0的位置. 题解: 因为是15次提问,其实可以想到二分,但是分别对0和1进行二分差不多要二十多次,所以可以对01或10进行二分,查找某一个01或10串的位置. #include<bits/stdc++.h> usin…
You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1≤i<n) such that si≠si+1. It is guaranteed that the answer always…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110…
Codeforces1107E 记忆化dp E. Vasya and Binary String Description: Vasya has a string \(s\) of length \(n\) consisting only of digits 0 and 1. Also he has an array \(a\) of length \(n\). Vasya performs the following operation until the string becomes empt…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3  描述:Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For             example, the text string B…
Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110…