摘要:
``` #include #include #include #include #include #include using namespace std; const int N=100005,inf=1r){ return 0; } int mid=(l+r)>>1; int u=node(a[mid],1); int ls=build(l,mid-1); if(ls){ link(ls,u,
阅读全文
posted @ 2020-05-17 17:28
prestige
阅读(215)
推荐(0)
摘要:
```cpp #include #include #include #define A 1000010 using namespace std; int f[A], w[A], v[A]; /* 0-1背包 */ int knapsack01(int n, int V) { memset(f, 0xc0c0c0c0, sizeof f); f[0] = 0; //需要装满 memset(f, 0,
阅读全文
posted @ 2019-11-12 09:50
prestige
阅读(192)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2486
阅读全文
posted @ 2019-10-31 23:08
prestige
阅读(198)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2146
阅读全文
posted @ 2019-10-31 19:37
prestige
阅读(203)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2371 cpp 本题就是同余最短路模板题,再加上差分求答案的核心思想即可. Code: include include include include include include include using namespace
阅读全文
posted @ 2019-10-31 19:35
prestige
阅读(177)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1505 cpp 本题讲一下取反操作:sum首先取反,max等于取反后的min,min等于取反过的max,那么直接把max,min互换然后分别取反就行了,另外标记直接 xor 1. Code: include include inc
阅读全文
posted @ 2019-10-23 13:23
prestige
阅读(176)
推荐(0)
摘要:
题面:http://poj.org/problem?id=2763 cpp 区间求和,修改单边.不加快读见祖宗. Code: include include include include include include include include using namespace std; co
阅读全文
posted @ 2019-10-21 23:11
prestige
阅读(155)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P3106 cpp 首先以n为起点两边spfa,之后再判断所有的边是否在最短路上,以警告次数作为边权再次spfa. Code: include include include include include include using
阅读全文
posted @ 2019-10-20 23:50
prestige
阅读(177)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P4009 cpp 分层图,建k+1层分别表示满油到没油,然后根据当前点是否有加油站在层间建边即可. Code: include include include include include include using namesp
阅读全文
posted @ 2019-10-20 14:26
prestige
阅读(249)
推荐(0)
摘要:
```cpp 【题目描述】 原题来自:USACO 2009 Feb. Silver 牡 mǔ,畜父也。牝 pìn,畜母也。 ——《说文解字》 约翰要带 N 只牛去参加集会里的展示活动,这些牛可以是牡牛,也可以是牝牛。牛们要站成一排,但是牡牛是好斗的,为了避免牡牛闹出乱子,约翰决定任意两只牡牛之间至少
阅读全文
posted @ 2019-10-20 11:32
prestige
阅读(1465)
推荐(0)
摘要:
```cpp include include include include include include include include using namespace std; const int N=100005; int n,m,p; long long A[N+5],B[N+5]; in
阅读全文
posted @ 2019-10-20 11:15
prestige
阅读(97)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P4473
阅读全文
posted @ 2019-10-19 23:26
prestige
阅读(148)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1073 cpp 建三层图,下第一层表示买,下第二层表示卖,没下表示没有进行贸易,然后跑最长路即可. Code: include include include include include include include inc
阅读全文
posted @ 2019-10-18 13:14
prestige
阅读(146)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2966 cpp 本题直接在floyd的基础上加上最大点权即可.(先排序,保证点权最小) Code: include include include include include include include include u
阅读全文
posted @ 2019-10-17 20:57
prestige
阅读(98)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2532
阅读全文
posted @ 2019-10-17 12:57
prestige
阅读(143)
推荐(0)
摘要:
题面:https://www.luogu.org/problemnew/show/P2986 cpp Code: include include using namespace std; struct B { int t,ne,d; }a[200005]; int n,e,fr[100005],c[
阅读全文
posted @ 2019-10-16 20:00
prestige
阅读(124)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1099
阅读全文
posted @ 2019-10-16 19:58
prestige
阅读(85)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2607 cpp 没有上司的舞会+环套树(破环为链)。。。 Code: include include include include include include include include using namespace
阅读全文
posted @ 2019-10-15 21:02
prestige
阅读(90)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1600 cpp V1[x] : 以x为LCA的路径的起点的集合。 Spn[x]: 以x为路径起点的路径条数。 V2[x]: 以x为终点的路径的起点集合。 V3[x]: 以x为LCA的路径的终点的集合。 s[x]:以x为终点的路径起
阅读全文
posted @ 2019-10-15 20:08
prestige
阅读(119)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P3128 cpp 树上差分裸题,那么在这里再讲一下树上差分: 一、点差分 val[u]++,val[v]++,val[lca(u,v)] ,val[fa[lca(u,v)]] ; 这里是因为要有一条链上包含lca 二、边差分 val
阅读全文
posted @ 2019-10-14 20:13
prestige
阅读(107)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P4427 cpp 本题设ans[u][i]为1~u的路径上的节点深度的i次方和,这样查询答案时就是ans[u]+ans[v] ans[lca(u,v)] ans[fa[lca(u,v)]] Code: include include
阅读全文
posted @ 2019-10-14 19:11
prestige
阅读(290)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P5021 cpp 本题首先看到最小值最大就可以想到二分,即二分一个mid作为答案,设f[u]为以u为根的子树中,不选作赛道的边最大为多少,因为赛道的选定只有两种情况,一是继续连向根的父亲,二是从儿子到根再到儿子,那么f[v]+w =
阅读全文
posted @ 2019-10-14 13:20
prestige
阅读(104)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P3398 cpp 本题有个很好的方法:显然当lca(a,b)在c,d路径上出现过,或者lca(c,d)在a,b路径上出现过,那么这两条路径一定重合. (注:一个点在路径上当且仅当这个点到这条路径两端点距离和等于这条路径长度.) Co
阅读全文
posted @ 2019-10-11 21:14
prestige
阅读(120)
推荐(0)
摘要:
```cpp 题面:https://www.luogu.org/problem/P1379 本题直接双向bfs,那么双向bfs就是把初始状态和终止状态都放进队列里,然后将二者设定为不同的方向,同时跑bfs,若目的状态和当前状态相同,目的状态无需再次入队,若目的状态和当前状态方向相反,那么直接输出答案
阅读全文
posted @ 2019-10-11 20:14
prestige
阅读(147)
推荐(0)
摘要:
```cpp include include include include include include include include using namespace std; const int N=51000005; char a[N]; int n,ans[N],anss,ma[N 2]
阅读全文
posted @ 2019-10-11 14:29
prestige
阅读(112)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P4421 cpp 本题把所有可能的子串全部做一遍字符串哈希,然后判断一波即可. Code: include include include include include include include include using
阅读全文
posted @ 2019-10-10 20:20
prestige
阅读(169)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P5018 cpp 本题直接写一个树上hash水过。。。 Code: include include include include include include include include include define ull
阅读全文
posted @ 2019-10-10 18:24
prestige
阅读(104)
推荐(0)
摘要:
```cpp include include include include include include define ull unsigned long long using namespace std; ull base=131,a[10005],mod=212370440130137957
阅读全文
posted @ 2019-10-10 13:15
prestige
阅读(166)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P3469 cpp 本题算答案的时候是很有技巧的,设u为割点,先算一遍以u子节点v为根的子树对外面所有点的答案,然后再把u和所有v作为一个整体,算以u为根的子树对外面的答案. 注意:这里的割点u要单独算. Code: include
阅读全文
posted @ 2019-10-09 20:30
prestige
阅读(105)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P5058
阅读全文
posted @ 2019-10-09 19:32
prestige
阅读(164)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2220 cpp 如题,这真是一道简单题. 很容易想到如果没有限制条件ans=(1+2+...+n) (1+2+...+n) ... (1+2+...+n) 那么如果有限制条件的话直接在括号里减去相应的限制条件即可. Code: i
阅读全文
posted @ 2019-10-09 12:37
prestige
阅读(115)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/CF766D ```
阅读全文
posted @ 2019-10-08 20:55
prestige
阅读(170)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1196
阅读全文
posted @ 2019-10-08 19:34
prestige
阅读(133)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P5020 本题如果a数组中有一个数可以被其它数表示出来,那么就可以不选它,然后就变成了完全背包裸题. Code: #include<iostream> #include<cstdio> #include<cstring> #incl
阅读全文
posted @ 2019-10-08 18:36
prestige
阅读(143)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1280
阅读全文
posted @ 2019-09-30 20:39
prestige
阅读(195)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1330 cpp 本题直接将相邻点染成不同的颜色,遇到染不了的就输出Impossible 然后每次统计染色点数少的加起来就行了. Code: include include include include include inclu
阅读全文
posted @ 2019-09-30 13:18
prestige
阅读(122)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P2679
阅读全文
posted @ 2019-09-30 06:44
prestige
阅读(103)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1351 cpp 本题可以直接枚举每个点所相连的点,因为子 父 子距离刚好是2,所以最大权值就由儿子中的权值最大值和权值次大值的乘积来提供,而和可以直接统计,最后乘2即可,因为联合权值的产生是成对的. Code: include i
阅读全文
posted @ 2019-09-30 06:14
prestige
阅读(166)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1314 cpp 本题直接二分W,当Y s,那么增加W来减小Y,当Y include include include include include using namespace std; const int N=200005;
阅读全文
posted @ 2019-09-29 13:32
prestige
阅读(114)
推荐(0)
摘要:
题面:https://www.luogu.org/problem/P1315 cpp 本题的算法是贪心,可以每次讨论在哪一段使用氮气加速器惠及的人最多,然后做k次即可. 这里需要注意的是:统计人数时arrive[i] =last[i]+1才可以使用 而找到在第k个站台使用后,k后面的站台的arriv
阅读全文
posted @ 2019-09-27 13:29
prestige
阅读(165)
推荐(0)