线段树&网络流&后缀数组etc
文章平均质量分 76
ccyy-
这个作者很懒,什么都没留下…
展开
-
HN OJ 13375 Flowery Trails (spfa的路径遍历)
题意:就是要你求出所有最短路径上的边之和,然后把结果乘以2 思路:spfa上有一个定理:对于给定的一条边,如果从源点到该边起点的最短距离+起点到该边的最短距离+该边的权值=最短距离,那么说明该边是最短路上的边! 转自:http://blog.csdn.net/u012313382/article/details/47400247 [cpp] view pl转载 2015-08-22 19:58:58 · 414 阅读 · 0 评论 -
【树状数组】专题+模板
先放模板。。。 #define lowbit(x) (x) & (-x) const int N=1005; const int M=1e9+7; int dp[N][N],c[N][N]; int a[N],r[N],w[N]; bool cmp(int b,int c) { return a[b]<a[c]; } void update(int i,int j,int value原创 2015-12-02 20:07:23 · 1011 阅读 · 4 评论 -
hdu5489(删除一段后的最长上升子序列长度)LIS
#include using namespace std; const int maxn = 1e5+5; int a[maxn]; int g[maxn]; int f[maxn]; int h[maxn]; int c[maxn]; int d[maxn]; const int INF = 0x3f3f3f3f; //#define LOCAL int main() { #ifdef原创 2015-10-01 10:17:49 · 1143 阅读 · 0 评论 -
poj1236|poj3177 tarjan,强联通,有向/无向
强连通是指内部任意点出发都能到达其余各点。 至于这题为什么要用连通块缩点,看完下面这张图就明白了。。 #include #include #include #include//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0}; #include//int gcd(int a,int b){return b?gcd(b,a%b):a;} #include原创 2016-04-04 14:56:40 · 1574 阅读 · 0 评论 -
求矩形并的面积(线段树)【模板】
#include #include #include #include #include #include using namespace std; const int N=210; struct node{ int left,right,c; //c : 区间被覆盖的层数, m: 区间的测度 double m; }tree[N*4]; struct Line{ doub转载 2016-01-14 23:36:41 · 362 阅读 · 0 评论 -
巴什博弈+威佐夫博弈+Nim博弈
巴什博弈 只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。 很容易想到当n%(m+1) 这个游戏还可以有一种变相的玩法:两个人轮流报数,每次至少报一个,最多报十个,谁能报到100者胜。 威佐夫博弈 有两堆各若干个物品,两个人轮流从某一堆或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜。 如果转载 2016-02-06 17:53:51 · 566 阅读 · 0 评论 -
询问某区间内有多少满足某个要求的/某区间以某式子计算出的值(莫队算法,不修改只询问区间)
我觉得能用线段树就用线段树吧,实在用不了了再来考虑莫队算法,比如下面两道题: http://codeforces.com/contest/617/problem/E (询问某区间内有多少个子区间的异或值是K) http://www.lydsy.com/JudgeOnline/problem.php?id=2038 (询问某区间内取到一对值相等的数的概率) http://codefo原创 2016-02-05 00:10:28 · 989 阅读 · 0 评论 -
【欧拉函数】集合
给一个正整数,其中,求使得为质数的的个数,。 其实挺难看出这题要用欧拉定理做的。 欧拉函数φ:φ(n)表示1 … n中与n互质的整数个数。即: for(int i=1;i if(gcd(i,n)==1) s++; (先考虑x求使得=1的的个数,那么就可以枚举y,然后s+=φ(y)来得到结果了。当然也可以用前缀和来一步求。 那么怎么把原题和欧拉函原创 2016-04-18 22:11:47 · 596 阅读 · 0 评论 -
连续看几天电影 最多能获得的值【线段树模板】
去年秋天做的题目,来源忘了。。 大意是,小镇会连续放n天电影,每天都会放一部编号为x[i]的电影,观看后能获得的对应的值是y[x[i]]。有一个人只能挑连续的几天看电影,并且相同编号的电影他看了超过一遍就会厌倦,这时就会“恢复”成“他没有看过这部电影”的状态(即把这部电影获得的值取消了),如果第一次看就会加上对应的值。问最多能获得多少值? 并且这题无法用树状数组。 #include #def原创 2016-01-24 18:14:54 · 614 阅读 · 0 评论 -
路数有限制(w的倍数)的最短路,【二维dijkstra】 双重限制并输出路径和方法数
比一般的dijkstra数组多了一维。 #include #include #include//ll dx[4]={0,0,-1,1};ll dy[4]={-1,1,0,0}; #include// #include #include #include #include #include #include #include #define mod 1原创 2016-03-31 12:07:15 · 532 阅读 · 0 评论 -
【Jan.Challenge】持续时刻变化的线段树(某时刻领先选手的位置)
两种方法:[线段树+二分] / [ 队列]原创 2016-01-14 21:04:59 · 477 阅读 · 1 评论 -
hdu5452 Minimum Cut(最近公共祖先LCA+差分前缀和)
Given a simple unweighted graph G (an undirected graph containing no loops nor multiple edges) with n nodes and m edges. Let T be a spanning tree of G. We say that a cut in G respects T if原创 2015-09-23 23:55:58 · 412 阅读 · 0 评论 -
swerc2014 Book Club(二分图匹配)
Porto’s book club is buzzing with excitement for the annual book exchange event! Every year, members bring their favorite book and try to find another book they like that is owned by someone willing t...原创 2015-09-02 10:02:02 · 1038 阅读 · 2 评论 -
hihocoder 1166 交换代数|HDU 4870 Rating 等(区间翻转,高斯消元求期望)
少女幽香这几天正在学习交换代数,然而她什么也没有学会,非常痛苦。于是她开始玩起了一个简单的小游戏,来放松一下。 地面上一共有n个球,一开始有一些是黑色的,有一些是白色的。每次她随机选择一个区间(一共有n(n+1)/2个区间,每个区间有相等的概率被选择),把这个区间的颜色反转,即将该区间中白球变黑球,黑球变白球。 现在她想要知道期望情况下,多少次反转能够使得整个区间都是白色的。 输入 第原创 2015-05-12 11:26:35 · 851 阅读 · 0 评论 -
【codechef】Common Strings(后缀数组)
You are given two strings A and B. Find the number of distinct strings which appear in both A and B . A string s is said to appear in S iff s is a substring (appears contiguously) of S. Input原创 2015-09-03 18:38:11 · 471 阅读 · 0 评论 -
poj1743(后缀数组)
转自:http://www.cnblogs.com/ziyi--caolu/p/3195342.html http://poj.org/problem?id=1743 题意:给出一串字符,求不重合的最长重复子串.......... 我自己的一点想法:编完后发现,其实就是将height值分组,然后记录在二分答案时满足height值>=p的sa[i]的最大最小值,转载 2015-08-21 14:53:32 · 430 阅读 · 0 评论 -
hdu 2768 二分图匹配(难想到)
题意:有v个观众,每个人投给自己喜欢的猫(或者狗)和讨厌的狗(或者猫),如果出现喜欢的和别人讨厌的相同,则其中一人会不满意。 现要求得是最大满意的观众是多少。 方法:根据出现矛盾的两个观众序号建边。现在选择最多的顶点,要求各个顶点之间没有线相连,即不出现矛盾。就是求最大独立集。 最大匹配:二分图G中,找出边数最大的子图M,使得M中各条边均无公共顶点,则M为最大匹配。可用匈牙利算法求得。转载 2015-10-02 23:58:09 · 439 阅读 · 0 评论 -
【codechef】Nikitosh and xor(线段树)
画家 Nikitosh 有一个含 N 个元素的数组 A,下标从 1 开始。他想要找出下面式子的最大值: (A[l1] ⊕ A[l1 + 1] ⊕ · · · ⊕ A[r1]) + (A[l2] ⊕ A[l2 + 1] ⊕ · · · ⊕ A[r2]) 其中,1 ≤ l1 ≤ r1 因为 Nikitosh 是一个画家而不是一个数学家,他需要你帮忙解决这个问题。 输入格式 输入数据原创 2015-09-16 22:24:20 · 597 阅读 · 1 评论 -
zoj1505 双向bfs
#include #include #include #include #include #include #include #include #include #include #include #include #define MID(x,y) ( ( x + y ) >> 1 ) #define L(x) ( x << 1 ) #define R(x) ( x <<转载 2015-09-19 10:16:52 · 350 阅读 · 0 评论 -
【codechef】 Special Economic Zone(二分图匹配,难想到)
Input: 6 5 1 2 2 3 4 5 5 6 6 4 Output: 1 Explanation Ciel will select city 1 and 3 as SEZ. So x = 2 (city 1 and 3), y = 1 (city 2), x - y = 1. http://www.codechef.com/MAY15/problems/SEZ/原创 2015-05-22 14:46:41 · 532 阅读 · 0 评论 -
HDU4778 Gems Fight!(记忆化搜索+博弈)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4778 题目大意:有B个包裹,里面有各种颜色的GEM,共有G个颜色。Alice和Bob轮流挑选包裹放到一个地方,如果挑选出来的同种颜色的GEM超过S个,当前回合者可以得分,每超过S个得一分。如果在回合内得分了,可以额外进行一个回合。问Alice的得分减去Bob的得分最大是多少。 #include转载 2015-10-13 22:22:12 · 693 阅读 · 0 评论 -
hdu5468 A Puzzled Elena (容斥原理)
题意:给定一棵树,求这个节点的所有子树与它互质的节点(包括他本身)的个数. http://acm.hdu.edu.cn/showproblem.php?pid=5468 #include #include #include #include//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0}; #include//int gcd(int a,int b原创 2015-10-24 15:17:58 · 756 阅读 · 0 评论 -
CF432D 求等于原串前缀的后缀子串,输出子串的长度和出现次数
给一个字符串,求等于原串前缀的后缀子串,输出子串的长度和出现次数。 再普及一下后缀数组的height:http://www.mamicode.com/info-detail-1068381.html #include #define ll long long #define inf 0x7fffffff #define mod 1000000007 using namespace std;原创 2017-03-21 01:57:35 · 631 阅读 · 0 评论