The Problem to Slow Down You Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=141572 Mean: 给你两个字符串,求这两个字符串相同回文串的匹配对数. analyse: 每个字符串建一棵回文树,分别从0结点和1结点两棵树一起往下dfs,对于同一条路径上的结点,一定是相同的回文,然后两个的数量相乘加到answer中. Time complexity: O(N)…
Description Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon, they planned to play a game with some stones. There were n stones on the ground and they were arranged as a clockwise ring. That is to say, the firs…
Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 675    Accepted Submission(s): 237 Problem Description Trader Dogy lives in city S, which consists of n districts. There are n - 1…
Clone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submission(s) : 8   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description After eating food from Chernobyl,…
这题建立一棵回文树,然后用dfs搜索答案,但是有一点需要注意,就是打vis的标记时,如果标记为1,那么在好几个节点都对同一个字符i打过标记,此时的搜索从字符i点回溯,回到它的父亲节点,搜索其它的字符,回溯的时候把vis[i]标记成0了,之前的vis[i]标记全被清空了,如果该父亲的其它字符节点下,有字符i的孩子,则此时统计就会出错.所以打vis标记的时候让vis++,而不是标记为0. #include <iostream> #include <stdio.h> using name…
#include <bits/stdc++.h> #define Sigma 30 #define MAXN 500010 #define int long long using namespace std ; int n, m, ans ; char s[MAXN], t[MAXN] ; struct PAM{ int rt0, rt1, last, sz, f[MAXN], ch[MAXN][Sigma], fail[MAXN], len[MAXN] ; void Init(){ sz =…
#include <bits/stdc++.h> #define Sigma 30 #define MAXN 500010 #define int long long using namespace std ; int n, m, ans1, ans2 ; char s[MAXN], t[MAXN] ; struct PAM{ int rt0, rt1, last, sz, f[MAXN], ch[MAXN][Sigma], fail[MAXN], len[MAXN] ; void Init(…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up because of the drought and the rabbit kingdom is facing a serious famine. The RRC(Rabbit Red Cross) organizes the distribution of relief grain in the disa…
Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件可过. #include<cstdio> #include<cstring> #include<algorithm> #pragma comment(linker, "/STACK:36777216") #define mt(a,b) memset(a,…
Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the weight. Your task is to deal with M operations of 4 types: 1.Delete an edge (x, y) from the tree, and then add a…
Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024 预处理出每个点八个方向能走的最远距离,然后枚举起点,枚举方向,每走一步都要枚举左转和右转的情况,因为预处理好了,所以可以直接算出来. #include<cstdio> #include<algorithm> using namespace std; ; char a[M][M]; ]; ,-,,,,,,-}; ,,,,,-,-,-}; b…
默默的签到 Osu! http://acm.hdu.edu.cn/showproblem.php?pid=5003 #include<cstdio> #include<algorithm> using namespace std; ]; int main(){ int t,n; while(~scanf("%d",&t)){ while(t--){ scanf("%d",&n); ;i<n;i++){ scanf(&qu…
意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖掉,输出max(0, 最大的收益) 然后给[u,v]路径上点点权+=val 思路: 树链剖分裸题.记录区间的最大最小值,→走的答案和←走的答案. 官方题解:点击打开链接 #pragma comment(linker, "/STACK:1024000000,1024000000") #inc…
G - Grade Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushrooms and ask him to grade each mushroom according to its weight. Suppose the weight of a mushroom is w, then it’s grade s is s = 10000 - (100 - w)^2What…
03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为sqrt(n),问题是怎么快速找到从i开始往前2种颜色.三种.四种...o[]种的位置. 离散化之后,可以边走边记录某个数最后一个出现的位置,初始为-1,而所要求的位置就等于 if(last[a[i]]==-1) 该数没有出现过,num[i][1] = i,num[i][j+1] = num[i-1…
思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’   'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就是模拟了. 注意:  ‘S’ 不是只有一个. 一个东西如果不是'P'在动的话要先判断周围有没有‘P’,有的话要先吃掉      'P'在动的时候如果一个位置周围有多个东西,都要吃掉. #include<iostream> #include<cstdio> #include<alg…
Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as he wanted. For example, some of the cloned objects…
传说的SB DP: 题目 Problem Description Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper and asks for your help. In eac…
题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Sony” 就输出“SONY DAFA IS GOOD!” ,大小写敏感. 思路 : 字符串查找,水题. #include <string.h> #include <stdio.h> #include <iostream> using namespace std ; ]; int…
1001 A Curious Matt 1002 Black And White 1003 Collision 1004 Dire Wolf 1005 Everlasting L 1006 Fluorescent 1007 GRE Words Once More! 1008 Happy Matt Friends 1009 Intersection 1010 Just A Mistake 1011 K.Bro Sorting…
K: 给你n个点以及n-1的条边, 问你最少要加多少条边,使得每两个点割去一条联通的边,还可以使的这两个点连通. 有个一个结论,最少添加的边数为(叶子节点数+1)/ 2. 我们可以只考虑叶子节点数应该怎么连了.按dfs序标号 a0 连 an/2  , a2连an/2+1  ·····.如果是奇数个,就把an连a1. 因为a0可以和别的节点连接,但是怎么样才是最好的,要每一个圈都尽量相交. #include <iostream> #include <cstdio> #include…
2017-09-24 20:15:22 writer:pprp 题目链接:https://nanti.jisuanke.com/t/17319 题意:给你一串数,给你一个处理方法,确定出这串数的权值,然后让你在这串数中找到最长非下降子序列,并算出对应的权值和 这道题花费我时间最长了,我还是不是特别理解LIS找到的一些模板也不怎么会使用,各种错误,趁这次机会好好理解一下 代码如下: //ac : L #include <iostream> #include <cstdio> #inc…
G: 要你去才Paul的年龄,Paul的年龄在1~n之间,你每猜一个Paul会告诉你,你猜的这个数和他年龄的gcd,问在最坏情况下最少要猜多少次. 题解: 什么是最坏情况,我们直到如果他的年龄是1的话, 你需要猜一边全部素数.所以很明显这就是最坏情况, 如果p,q是素数,p*q<=n, 我们就可以猜p*q,一次就可以去掉两个素数了. 所以这一题就变成了将1~n的素数分成m部分, 每一部分的乘积要小于等于n. #include <iostream> #include <cstdio&…
E: 模拟题,一开始有n个人(有男有女),对于子女来说线粒体DNA是继承母亲的.然后有m个操作(按时间顺序),一种就是给了父亲,母亲的ID,生了一个孩子(编号从n+1开始往下):还有一个就是 -x , 表示ID为x的人死亡.然后给了你k个信息 ,表示id 为 x 的DNA .问你最后存活的人的DNA是不是一样的. 题解:模拟一下 坑:k个给你的DNA,要标记为祖先的DNA 如果存活的人有一些是有DNA(一种),而一些是不知道的,这种情况是POSSIBLY…
B: 现在有一种新的2进制表示法,要你求出0~m-1的每个数的表示. 规则如下:n 是满足 m<=2n 最小数. 而0~m-1的数只能够用n-1个位和n个位来表示. 对于n个位表示的数来说不能有n-1个位表示的数前缀.(如果3表示101那么就不能有10去表示前面的数. 要求要全部数的位数加起来最小, 数从小到大排. 题解:我们先要求出n. 如果是m == 2n 来说.我们不会有n-1位来表示数. 证明:我们有 m/2 个 n-1位数,每一个n-1位数在尾部加上0或者1就可以变成n位的数, 1个n…
A: 给你一个矩阵求'/' 和 '\' 围成的图形,简单签到题,有一些细节要考虑. 题解:一行一行的跑,遇到'/'和'\' 就加0.5, 在面积里面的'.' 就加1.用一个flag来判断是否在围住的图形里面. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <cmath> #…
题目链接 题目大意 要你在[l,r]中找到有多少个数满足\(x\equiv f(x)(mod\; m)\) \(f(x)=\sum_{i=1}^{k-1} \sum_{j=i+1}^{k}d(x,i)*d(x,j)\) \(d(x,i)表示x的第i位数\) 题目思路 显然是数位dp,然而这个数位dp不能同时存x%m 和f(x)%m 这样会内存太大存不了,所以存差值即可 还有这个dfs的时候取模只取一次,不然会t,卡常严重 代码 #include<set> #include<map>…
题解: https://files.cnblogs.com/files/clrs97/19HKEditorial-V1.zip Code:(Part) A. Axis of Symmetry #include<cstdio> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int N=100010,inf=1000000010; int Case,…
回文树,也叫回文自动机,是2014年被西伯利亚民族发明的,其功能如下: 1.求前缀字符串中的本质不同的回文串种类 2.求每个本质不同回文串的个数 3.以下标i为结尾的回文串个数/种类 4.每个本质不同回文串包含的本质不同回文串种类 (本文参考自Palindromic Tree——回文树[处理一类回文串问题的强力工具],Palindromic Tree 回文自动机-回文树 解决回文串的神器) 下面介绍一些数组的意义 next[][]类似于字典树,指向当前字符串在两段同时加上一个字符 fail[]…
https://ac.nowcoder.com/acm/contest/886/C 题意: 给出一个串A , 集合S里面为A串的回文字串 , 现在在集合S里面找出多少对(a,b),b为a的字串 分析:回文字串嘛,先盲猜一波回文自动机:我们现在知道回文自动机的原理图可以得出 , 它其实是用两棵树顶点为0和1 假设现在对于一个   XXXabccbaXXX  现在对于查到的点a 的贡献 , 我们发现是说它向外的层数*向内的层数-1 ,比如现在a向外3层,向内2层,包括a.....a的答案有2*3-1…