摘要: 题意:https://ac.nowcoder.com/acm/contest/2995/D 思路: 和最大子串很像,dp[i]=max(dp[i-1]+a[i],a[i]),要不和前面连一起,要不就是重新打头 阅读全文
posted @ 2019-12-10 21:11 ZMWLxh 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 题意:https://ac.nowcoder.com/acm/contest/2995/E 给你一棵树,节点有权值,让你求所有路径max-min的和。 思路: 我们计算每个点的贡献,对于一个点,当它为某条路径的最大值是,一定在一个所有值<=它的连通块里。所有我们从小到大添边合并共享(两块的大小之积, 阅读全文
posted @ 2019-12-10 21:07 ZMWLxh 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 题意:https://www.luogu.com.cn/problem/P3195 思路:https://www.luogu.com.cn/problemnew/solution/P3195 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0) 阅读全文
posted @ 2019-12-08 11:05 ZMWLxh 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 题意:HDU1455 给出n个小木棒的长度,他们是又数根长度相同的木棒剪短得来的,问没剪短之前的木棒长度最短是多少. 思路: 见代码:https://www.cnblogs.com/fqfzs/p/9911110.html参考自 1 #include<bits/stdc++.h> 2 using n 阅读全文
posted @ 2019-12-05 21:26 ZMWLxh 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=1401 给你8*8的棋盘和4个棋子初始位置、最终位置,问你能否在8次操作后达到该状态。 思路: 双向BFS,起点开始正搜4步,终点倒搜4步,map标记。 1 #define IOS ios_base::syn 阅读全文
posted @ 2019-12-05 21:16 ZMWLxh 阅读(883) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=4117 思路:https://blog.csdn.net/u013306830/article/details/77586562 主要就是卡你内存,AC自动机的字典树得要用了再清空。 代码有点长吧。。。 1 阅读全文
posted @ 2019-11-29 21:40 ZMWLxh 阅读(708) 评论(0) 推荐(0) 编辑
摘要: 题意: 思路: 先建好整棵树。 遇到+val操作用dfn对区间+val 遇到加新点清空一下该点的点值(这里保证了之后查询的点肯定是清空过的) 差分+树状数组or线段树 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include 阅读全文
posted @ 2019-11-28 20:17 ZMWLxh 阅读(340) 评论(0) 推荐(1) 编辑
摘要: 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa sys 阅读全文
posted @ 2019-11-23 10:33 ZMWLxh 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 让DAG变成强连通就是把尾和头连起来,也就是入度和出度为0的点,添的边数:max(num_in==0,num_out==0) 阅读全文
posted @ 2019-11-22 21:01 ZMWLxh 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 这才是更一般的二分写法--HDU5412 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc 阅读全文
posted @ 2019-11-22 20:15 ZMWLxh 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa sys 阅读全文
posted @ 2019-11-22 18:18 ZMWLxh 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 题意:https://ac.nowcoder.com/acm/contest/882/E 给你01矩阵,有两种操作:1是把一个位置0变1、1变0,2是问你从第一行i开始,到最后一行j有几种走法。你只能不能向上走而且不能往回走。 思路: 01矩阵里每一行可以用一个矩阵表示向下有几种走法,i行到j行的的 阅读全文
posted @ 2019-11-16 22:24 ZMWLxh 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/group/ikIh7rsWAl/contest/259944/problem/G 给你一颗树(可能有好几棵),你每次最多只能去掉k个叶子节点,问你最多几次能去完。 思路: 按深度deep保存每个深度的节点个数,从前往后for一遍,过程中如果一个d 阅读全文
posted @ 2019-11-16 19:19 ZMWLxh 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/group/ikIh7rsWAl/contest/259944/problem/D 给你q个操作,4个数n,a,k,c,从n好位置开始每次加a的位置变成字符c,加到k次停止。 思路: 首先肯定是从下往上修改,改完就可以不再考虑该位置了。 1.对于a 阅读全文
posted @ 2019-11-16 19:12 ZMWLxh 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 题意: 有n个数,每个数都有价钱,连续的取可以获得len*len的利益,使利益最大。 思路: 三维DP,1、2、3维分别是第i个,剩余多少钱,从后往前连续的有几个。 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include 阅读全文
posted @ 2019-11-08 19:04 ZMWLxh 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=2594 如题。 思路: Next数组记录的是pos位置失配时要跑到哪里,所以最后得再添加一个字符‘#’。 连结两个串的中间加一些奇怪字符以保证next值不在同一个串中。 1 #define IOS ios_b 阅读全文
posted @ 2019-11-07 21:25 ZMWLxh 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=1695 直接上莫比乌斯模板。 1 #include <bits/stdc++.h> 2 using namespace std; 3 const long long maxn=100005; 4 5 long 阅读全文
posted @ 2019-11-07 20:31 ZMWLxh 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=2242 给你一个图,问你缩完点树上割边的做小绝对值差。 思路: 这题核算起来整整做了我一天(即24个小时)!!!一开始是MLE了近20发,然后TLE5、6发,再WA了一个晚上加一个下午。 有一种自闭是你突然对 阅读全文
posted @ 2019-11-07 18:06 ZMWLxh 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=2516 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win". 阅读全文
posted @ 2019-11-06 21:05 ZMWLxh 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=2458 问你二分图的最大团是多大。 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf i 阅读全文
posted @ 2019-11-06 20:53 ZMWLxh 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 最大团 = 补图的最大独立集; 最大独立集 = 顶点数 - 最大匹配; 所以最大团 = 顶点数 - 补图的最大匹配数; 阅读全文
posted @ 2019-11-06 20:18 ZMWLxh 阅读(334) 评论(1) 推荐(0) 编辑
摘要: 题意:https://www.nitacm.com/problem_show.php?pid=2266 vis记【x】【y】【dir】三个状态就行。 引用:https://blog.csdn.net/qq_37451344/article/details/80243077 1 #include<st 阅读全文
posted @ 2019-11-06 19:56 ZMWLxh 阅读(336) 评论(0) 推荐(0) 编辑
摘要: 点覆盖集:无向图G的一个点集,使得该图中所有边都至少有一个端点在该点集中。 最小点权覆盖集:在带点权无向图G中,点权和最小的点覆盖集。 点独立集:无向图G的一个点集,使得任何两个在点集中的点在图G中都不相邻。 最大点权独立集:在无向带权图G中,点权和最大的点独立集。 最小点权覆盖集=最小割=最大流 阅读全文
posted @ 2019-11-03 21:15 ZMWLxh 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=1540 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #in 阅读全文
posted @ 2019-11-03 14:57 ZMWLxh 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa sys 阅读全文
posted @ 2019-11-03 12:27 ZMWLxh 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa sys 阅读全文
posted @ 2019-11-03 12:25 ZMWLxh 阅读(348) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/gym/102394/problem/E 1操作是给你一串数,2操作是连结两个串(所以可能很长),问你最后一个串的值(知道最多的个数就很好算,关键计算个数) 思路: 对二操作建图,一开始还以为建出来的是树就可以直接BFS计算次数,自闭了好久,最后才发 阅读全文
posted @ 2019-11-03 11:23 ZMWLxh 阅读(1480) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/915/C 举个例子:假使排好序后a字符串是123456,b是456456,按照上述方法遍历,213456 ->312456->412356->(这是第一个字符的最大值,再往下变的话只能是5了,但不满足题意)—– 阅读全文
posted @ 2019-11-02 12:44 ZMWLxh 阅读(281) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=2082 阅读全文
posted @ 2019-11-02 09:18 ZMWLxh 阅读(202) 评论(0) 推荐(0) 编辑
摘要: D[i]=(i-1)*(D[i-1]+D[i-2]) 阅读全文
posted @ 2019-11-01 20:07 ZMWLxh 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题意: 移动木头盘不能a到c,必须a到b到c。 问你移动次数。 假设将n层塔从A经B挪到C需要f[n]步。那么具体的移动过程可以这样看:将上面n-1层从A经B挪到C需要f[n-1]步,再将第n层从A挪到B,需要一步,再将上n-1层从C经B挪到A,需要f[n-1]步,再将第n层从B挪到C,需要一步,再 阅读全文
posted @ 2019-11-01 19:44 ZMWLxh 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=1533 相邻的容量为inf,费用为1,S到m容量为1,费用为0 ,H到T容量为1,费用为0。 建图跑-最小费用最大流-就行了。 阅读全文
posted @ 2019-10-31 21:34 ZMWLxh 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 题意: Philosopher’s Walk 图,告诉你step返回位置。 思路: 按四个块DFS 阅读全文
posted @ 2019-10-31 10:36 ZMWLxh 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题意:https://blog.csdn.net/Ratina/article/details/95200594 思路: 首先我们知道最小生成树就是按长度枚举边,能连就连。 那么,如果这条边在最小生成树里,那我们只需要看比它短的边是不是已经使当前的u v连通,如果连通最少需要切掉几条(边权为1跑最小 阅读全文
posted @ 2019-10-31 10:21 ZMWLxh 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 题意:https://www.luogu.org/problem/P2756 阅读全文
posted @ 2019-10-28 20:18 ZMWLxh 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5980 b乘以GCD(a,b)之后,解方程就行了。 阅读全文
posted @ 2019-10-26 21:31 ZMWLxh 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5971 把已经告诉你的把能推测的都推测出来有矛盾就“NO”,剩下的跑二分图,矛盾就“NO”,剩下如果还有没有颜色的“NO”。 阅读全文
posted @ 2019-10-26 21:29 ZMWLxh 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5976 首先队友想出了分的越多答案越多。 我们就:2,3,4,5,6.。。多出来的尽量往小了加就行了。 阅读全文
posted @ 2019-10-26 21:26 ZMWLxh 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5973 根号5复制后200位就行了,因为BigDecimal不支持开根号,除法二分开根。 阅读全文
posted @ 2019-10-26 21:22 ZMWLxh 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <iostream>//pair 5 #include 阅读全文
posted @ 2019-10-26 09:41 ZMWLxh 阅读(160) 评论(0) 推荐(0) 编辑