P5043 【模板】树同构([BJOI2015]树的同构) 思路:树hash,先找树重心,重心最多两个,然后从以重心为根求出树的hash值,放进map里。 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi
题面 https://www.luogu.org/problem/P3501 题解 #include<cstdio>#include<iostream>#include<cstring>#define ri register int#define N 500050#define uLL unsigned long longusing namespace std;int n;char s[N];const uLL p=107;uLL sum1[N],sum2[N];uL
题面 https://loj.ac/problem/2072 题解 #include<cstdio>#include<iostream>#include<cstring>#include<vector>#include<map>#include<set>#include<algorithm>#define N 100500#define uLL unsigned long long#define ri register
#include<bits/stdc++.h>#define ll long long#define ull unsigned long longconst int inf = 0x3f3f3f3f;const int N = 4e5+7;const ll mod = 998244353;using namespace std;ull hash1=13331;ull ha[N],pp[N];ull getha(int l,int r){ if(l==0) return ha[r];
题目: 洛谷 3822 分析: 直接按题意模拟,完了。 将每次加 / 减拆成不超过 \(32\) 个对单独一位的加 / 减。 考虑给一个二进制位(下称「当前位」)加 \(1\) 时,如果这一位本来就是 \(0\) ,那么直接变成 \(1\) 。否则要考虑进位:向左(以后默认从右向左为低位至高位,与书写顺序相同)找到第一个为 \(
字符串哈希 #include<iostream> #include<cstdio> #include<cstring> #include<set> using namespace std; typedef unsigned long long ull; int n; char str[1510]; set<ull> S; ull str_hash(char str[]) //2^64自然溢出 {
一个字符串可以表示为: ,故当哈希冲突率低的时候,可以将字符串唯一表示为一个数字,本题线段树就是维护区间和。 #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<queue> #include<stack> using namespace std; const in
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 Now you are back,and have a task to do:Given you a string s consist of lower-case English letters only,denote f(s) as the number of distinct sub-string of s.And you have some query,each time you should c
---恢复内容开始--- 话说要学反演了,contest一题都搞不定,整理题目暂且搁置,数学笨蛋来学一下数学_(:з」∠)_ ---恢复内容结束--- 是的,预习看了半天教学,没有整理,做题又都不会,我能怎么办呢_(:з」∠)_我只能补题了呀 HDU-3903 结论题,易证 首先由余弦定理,abc都是有理数所以co
题意:求最长公共子串 思路:把两个串Hash,然后我们把短的作为LCS的最大可能值,然后二分长度,每次判断这样二分可不可以。判断时,先拿出第一个母串所有len长的子串,排序,然后枚举第二个母串len长度字串,二分查找在第一个母串的子串中存不存在。 代码: #include<cmath>#include<stack>#include<
\(\verb|bzoj4892 [TJOI2017]DNA|\) 给定一个匹配串和一个模式串,求模式串有多少个连续子串能够修改不超过 \(3\) 个字符变成匹配串 \(len\leq10^5\) hash 枚举子串左端点,hash 求 lcp 枚举断点,接着跳过断点,记作一次修改,最多修改 \(3\) 次。特判修改 \(3\) 次后剩余部分是否相等。
第一注意整数溢出的情况 第二,递归函数的含义要非常的明确,这样才能真正明白它的含义,以及确定出边界条件 第三,如果一个指令有可能不执行,那么要放到循环体的里面去 下面是代码 #include<iostream>#include<string>using namespace std;typedef unsigned __int64 ULL;ULL cnt = 1;stri
题目描述: 大皮出行,妹子成群,似乎这种事早已经司空见惯了。 大皮最终还是厌倦了这样的⽣活,懂得了节制,他希望每次恰好只有三个妹子陪他。 大皮有 $n$个妹子,编号为$0$到$n-1$ ,大皮需要次从$n$个中选出三个来愉悦身心。 那么问题来了,有许多妹子为了得到大皮的欢心,产生了冲突,这样的冲突
题目 https://ac.nowcoder.com/acm/contest/2?&headNav=www#question 解析 我们对矩阵进行二维hash,所以每个子矩阵都有一个额hash值,二分答案然后O(n^2) check 枚举矩阵终点,记录每个hash值与有两个一样的就true AC代码 #include<bits/stdc++.h> using namespace std; typedef unsig
bzoj 4811 由乃的OJ 考虑树链剖分. 树剖后用一颗线段树维护一段连续区间,类似于一个函数,各位上进入 \(0/1\) ,输出的数字分别是什么.注意到最多只有 \(64\) 位,可以用一个 \(unsigned\ long\ long\) 的大数状压表示,合并两段区间时推导一下可以做到 \(O(1)\) . 注意 \(3 种\)位运
GukiZ and Binary Operations 显然我们要拆位, 因为每位都独立, 然后问题就变成能用dp求的东西,然后用矩阵快速幂优化一下。 注意mod为1的情况。 #include<bits/stdc++.h>#define LL long long#define fi first#define se second#define mk make_pair#define PLL pair<LL, LL>#define
Oulipo 1 #include<bits/stdc++.h> 2 #define N 1000000+5 3 using namespace std; 4 typedef unsigned long long ULL; 5 const int b=55; 6 ULL n,m,s,ans,p[N],sum[N]; 7 char s1[N],s2[N]; 8 9 int main() { 10 scanf("%s",s1+1),scanf(&q