http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接退出!题目给了另一种相等的条件. #include<bits/stdc++.h> using namespace std; #define ll long long ]; ]; bool isequal(char *sb,int slen,char *tb,int tlen){ if(slen!=…
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include<cstring> using namespace std; #define ll long long ; bool cmp(char a[],char b[],int l) { bool ans=true; ;i<l;i++)if(a[i]!=b[i])ans=false; return an…
题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价,或者al和br等价且ar和bl等价. 实际上非常水.直接依照题意模拟写个递归分治就能够求.比赛的时候总认为这样暴力写会TLE,由于算了下大概是4^(log2(n))的复杂度.也就是n^2.所以比赛的时候就想了下.将两个串都依照题意转化为字典序最小串(循环节的最小表示法)然后比較a和b的两个最小表示法…
题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #inclu…
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the same size a1 and a2…
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断是否等价. 等价的含义为: 若长度为奇数,则必须是相同串. 若长度是偶数,则将两串都均分成长度为原串一半的两个子串l1,r1和l2,r2,其中l1和l2等价且r1和r2等价,或者l1和r2等价且l2和r1等价. analyse: 直接按照题意模拟写个递归分治就行.比赛的时候总觉得这样暴力写会TLE,…
D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/B Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are…
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/B Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are…
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal l…
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal l…
Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出两个字符串,确定是否相等.一个字符串分割成相同大小的两半a1和a2,另一个字符串分割成相同大小的成两半b1和b2. 以下是正确的:a1相当于b1 ,a2相当于b2a1相当于b2 ,a2相当于b1 Sample Input Input aabaabaa Output YES Input aabbaba…
Equivalent Strings   E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length ar…
B. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal l…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalen…
感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #include <iostream> #include <cstring> #define clr(x,c) memset(x,c,sizeof(x)) using namespace std; const int N = 200005; char s[N], t[N]; int sc[30],…
A题,超级大水题,根据有没有1输出-1和1就行了.我沙茶,把%d写成了%n. B题,也水,两个矩形的长和宽分别加一下,剩下的两个取大的那个,看看是否框得下. C题,其实也很简单,题目保证了小三角形是正三角形,一个正三角的面积=l*l*(1/2)*cos(30),由于只要算三角形个数,把六边形扩成一个大三角,剪掉三个小三角,除一下系数就没了.就变成了平方相减. D题,根据定义递归.然后注意奇数就行了.我沙茶,没加第一种判断dfs(a+len,len,b+len) && dfs(a,len,b…
Submit Status Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves…
A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consi…
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation saisbi is saved into a new string sn + …
A. Petya and Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of u…
Codeforces 848C Goodbye Souvenir Problem : 给一个长度为n的序列,有q个询问.一种询问是修改某个位置的数,另一种询问是询问一段区间,对于每一种值出现的最右端点的下标与最左端点的下标的差值求和. Solution : 定义pre[i] 为 第i个位置的数字上一次出现位置,对于询问l, r 就是对于所有满足 l <= pre[i] < i <= r 的点求和,权值为 i - pre[i]. 因此可以把这个看作是三维偏序的问题,第一维时间,第二维,第三…
Codeforces 938G Shortest Path Queries 一张连通图,三种操作 1.给x和y之间加上边权为d的边,保证不会产生重边 2.删除x和y之间的边,保证此边之前存在 3.询问x到y的路径异或最小值 保证图在任意时刻连通 首先连通图路径异或相当于从x到y的任意一条路径再异或上若干个环得到的,只要在dfs过程中把非树边成的环丢到线性基里就好了,其他环一定可以通过这些环异或组合出来 有加边删边操作怎么做呢?线段树时间分治!注意到不能保证在线段树的任意一个节点图是连通的,需要用…
Codeforces 题面传送门 & 洛谷题面传送门 u1s1 感觉这道题放到 D1+D2 里作为 5250 分的 I 有点偏简单了吧 首先一件非常显然的事情是,如果我们已知了排列对应的阶梯序列,那么排列中每个极长的连续阶梯段就已经确定了,具体来说,由于显然极大的连续段之间不能相交,因此假设 \(a\) 为 \(p\) 的阶梯序列,对于 \(a\) 数组中每个值相同的极大连续段 \([l,r]\),显然我们只能每 \(a_l\) 个元素将其划分成 \([l,l+a_l-1],[l+a_l,l+2…
Codeforces 题面传送门 & 洛谷题面传送门 神仙题. 首先我们考虑按照这题的套路,记 \(t_i\) 表示 \(i\) 上的果子数量减去其儿子果子数量之和,那么对于一个合法的放置果子的方案,必然有 \(t_i\ge 0,\sum\limits_{i=1}^nt_i=X\),而根据隔板法,对于一个大小为 \(s\) 的连通块,分配该连通块中的 \(t_i\) 的方案数为 \(\dbinom{X+s-1}{s-1}\),因此假设大小为 \(i\) 的连通块个数为 \(c_i\),那么答案即…
题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\),使得这个新串包含所有长度为\(k\)的01串(这样的字符串有\(2^k\)个) 题解:首先来证明对于任何的串,这个\(k\)的值不会超过9 若\(k=10\),由所有字符串的长度总和不超过100,因此在初始的\(n\)个串里,互不相同的长度为\(k\)的子串不超过100个.又由于每次连接最多能产生…
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[然而卡掉本弱还是轻轻松松的] 题目链接:616F - Expensive Strings 题目大意:给出\(n\)个字符串\(t_i\)以及\(n\)个数\(c_i\),定义\(p_{s,i}\)为字符串\(s\)在\(t_i\)中出现的次数,\(f(s)=\sum_{i=1}^{n}c_i\cdo…
洛谷 Codeforces 建议阅读这篇博客作为预备.无耻地打广告 思路 与bzoj4025很相似,思路也差不多,可以看上面那篇博客. 仍然是用二分图的充要条件:没有奇环. 然而这题难在每条边的存在时间不固定,无法一开始知道. 可以每次在加入这条边的时间点判断能否成功修改,确定接下来一段时间它的颜色是什么. 具体见代码. 代码 #include<bits/stdc++.h> namespace my_std{ using namespace std; #define pii pair<i…
假如两个区间的26的字母出现的位置集合分别是 A1,B1,A2,B2,....., 我们再能找到一个排列p[] 使得 A[i] = B[p[i]] ,那么就可以成功映射了. 显然集合可以直接hash,排序一下hash值就可以判断是否匹配了.... 虽然不知道为什么要卡19260817,但反正我是坚决不写双hash的,最后随便换了一个大模数(甚至都不是质数2333)然后就过了... Discription You are given a string s of length n consistin…
[题目链接] https://codeforces.com/contest/452/problem/E [算法] 构建后缀数组 用并查集合并答案即可 时间复杂度 : O(NlogN) [代码] #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; ; ; #define rint register int…
题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚举满足条件的字符进行替换. 代码: #include<iostream> using namespace std; int main (void) { string s;cin>>s; int n = s.length(); for(int i = 1; i < n; i++){…