7.15外培记录
sanghaozhe
·
·
个人记录
7.15
上午
1.P8817 [CSP-S 2022] 假期计划
已知算法 双向dfs
(1)floyd求连通性建新图
(2)n^2求点对
*(3)每个终点保留3条边
(4)暴力匹配
O(n^2+nm)
2.P2324 [SCOI2005] 骑士精神
已知算法 IDA*
(1)估价为不在原位个数
(2)dfs
(3)可用双向dfs优化
3.P11232 [CSP-S 2024] 超速检测(AC)
(1)超速不是在开始就是在结束,找头尾及其测速仪,记录测速仪区间
(2)区间右端点排序,每次取右端点贪心
4.P2619 [国家集训队] Tree I
算法:最小生成树,*WQS二分
(1)求MST
*(2)将白边加边权重求MST,二分知道白边为need
5.P1484 种树
*用双向链表,每次取后将前后点打包成一个
6.P7962 [NOIP2021] 方差(AC)
(1)\Sigma (x_i-{\frac {\Sigma x} n})^2
= \Sigma[x_i^2-\frac {2x_i\Sigma x} n+\frac {(\Sigma x)^2} {n^2}]
=\Sigma x^2 - \frac {2 \Sigma x} n \Sigma x + \frac {(\Sigma x)^2} {n^2} \cdot n
=\Sigma x^2 - \frac {(\Sigma x^2)} n
(2)每次操作实质为调换差分数组
(3)感性理解差分数组先降后升答案最小
(4)差分数组排序,分放左边/放右边dp
(5)tips:值域较小,差分中存在大量0;滚动数组
7.P1080 [NOIP 2012 提高组] 国王游戏(AC)
设\Pi=k,i在i+1前
即 max(\frac {ka_i} {b_{i+1}}+\,\frac k {b_i}) < max(\frac {ka_{i+1}} {b_i},\frac k {b_{i+1}}),
即max(a_ib_i,b_{i+1})<max(a_{i+1}b_{i+1},b_i),
即$a_ib_i<a_{i+1}b_{i+1}$。
按$a_ib_i$升序即可。
### 下午
#### 1.[P1084 [NOIP 2012 提高组] 疫情控制](https://www.luogu.com.cn/problem/P1084)
(1)尽量向上跳,分各子树考虑
\***(2)二分答案**
(3)分能否到达分类
#### 2.[P1967 [NOIP 2013 提高组] 货车运输](https://www.luogu.com.cn/problem/P1967)(AC)
\***(1)找最大生成树(反证法可证)**
(2) 转化为LCA
#### 3.[P1712 [NOI2016] 区间](https://www.luogu.com.cn/problem/P1712)
(1)降序加入各区间
\***(2)第一次出现某点覆盖区间数>=m时,其len.max-len.min为该len.max对应的差值中最大的**
#### 4.[P1502 窗口的星星](https://www.luogu.com.cn/problem/P1502)(AC)
\***(1)区间转化为点**
(2)扫描线
#### 5.[P3157 [CQOI2011] 动态逆序对](https://www.luogu.com.cn/problem/P3157)(AC)
\***三维偏序**
树状数组+归并
#### 6.[P2824 [HEOI2016/TJOI2016] 排序](https://www.luogu.com.cn/problem/P2824)(AC)
(1)二分答案
\***(2)\*线段树处理\*01排序**
#### 7.[P9871 [NOIP2023] 天天爱打卡](https://www.luogu.com.cn/problem/P9871)
(1)n^3dp
(2)n^2logn树状数组优化
\***(3)nlog^2n线段树优化**
#### 8.[P4556 【模板】线段树合并 / [Vani 有约会] 雨天的尾巴](https://www.luogu.com.cn/problem/P4556)
(1)树上差分
\***(2)在每个节点开动态线段树记录种类**
\***(3)线段树合并(pa=sum(son))**
---
---
## 7.16
### 上午
#### 1.[P3224 [HNOI2012] 永无乡](https://www.luogu.com.cn/problem/P3224)(AC)
已知算法 线段树合并
(1)每点开权值线段树
(2)并查集+线段树合并
#### 2.[P1168 中位数](https://www.luogu.com.cn/problem/P1168)(AC)
\***(1)对顶堆**
(2)线段树(?)
#### 3.[P3384 【模板】重链剖分 / 树链剖分](https://www.luogu.com.cn/problem/P3384)(AC)
(1)dfs1找size,depth,father,maxson
(2)dfs2找dfn,top
(3)lca+线段树
#### \*4.[P7735 [NOI2021] 轻重边](https://www.luogu.com.cn/problem/P7735)
#### 5.[P2048 [NOI2010] 超级钢琴](https://www.luogu.com.cn/problem/P2048)(AC)
(1)预处理前缀和
(2)用RMQ求max
(3)用堆求最大值,其中加入其余项
#### \*6.[P5283 [十二省联考 2019] 异或粽子](https://www.luogu.com.cn/problem/P5283)
同上,其中求最大值部分需要Trie
### 下午
#### 1.字符串哈希(略)(AC)
#### 2.kmp(略)(AC)
#### 3.AC自动机(略)(AC)
#### 4.[P4052 [JSOI2007] 文本生成器](https://www.luogu.com.cn/problem/P4052) & [U281171 【KMP+状态机||AC自动机】密码](https://www.luogu.com.cn/problem/U281171) (削弱版)(AC)
dp[i][j]表示到第i位,匹配到j的方案数
#### 5.[P2414 [NOI2011] 阿狸的打字机](https://www.luogu.com.cn/problem/P2414)(AC)
(1)建Trie树和Fail树
(2)求Trie树链在Fail树中的出现次数
#### 6.[P3805 【模板】Manacher](https://www.luogu.com.cn/problem/P3805)
(1)记录以每个点为中点的max回文串
(2)记录右端最靠右的回文串进行拓展
#### 7.[P5410 【模板】扩展 KMP / exKMP(Z 函数)](https://www.luogu.com.cn/problem/P5410)
---
---
## 7.17
### 上午
#### 1.[P4568 [JLOI2011] 飞行路线](https://www.luogu.com.cn/problem/P4568)(AC)
法1:dp+最短路
\***法2:分层图最短路**
#### 2.[P4180 [BJWC2010] 严格次小生成树](https://www.luogu.com.cn/problem/P4180)
(1)找最小生成树
(2)记录路径上最大值及\***次大值**
#### 3.[P3275 [SCOI2011] 糖果](https://www.luogu.com.cn/problem/P3275)(AC)
已知算法 \***差分约束**
(1)建图,(u,v,w)表示(f[u]<=f[v]+w)
(2)缩点判无解
(3)求最长路
#### 4.[P5905 【模板】全源最短路(Johnson)](https://www.luogu.com.cn/problem/P5905)(AC)
(1)从超级源点跑一边负权最短路
(2)建新图,w'(u,v)=w(u,v)+l(u)-l(v)
(3)n次dijkstra
#### \*5.[P3953 [NOIP 2017 提高组] 逛公园](https://www.luogu.com.cn/problem/P3953)
#### 6.[P3225 [HNOI2012] 矿场搭建](https://www.luogu.com.cn/problem/P3225)
缩点板子
#### 7.[P4782 【模板】2-SAT](https://www.luogu.com.cn/problem/P4782)(AC)
算法\***2-SAT**
(1)建边
(2)tarjan
(3)看0/1情况的拓扑序(scc序倒序)
### 下午
#### 1.[P3825 [NOI2017] 游戏](https://www.luogu.com.cn/problem/P3825)
已知算法 2-SAT
(1)对非x赛事直接进行2-SAT
(2)对x赛事枚举为a或为b跑2^d次2-SAT
#### 2.[P3209 [HNOI2010] 平面图判定](https://www.luogu.com.cn/problem/P3209)(AC)
已知算法 2-SAT
\***(1)该平面图最多3n-6条边**
(2)n^2建2-SAT图并跑2-SAT
#### 3.[P4768 [NOI2018] 归程](https://www.luogu.com.cn/problem/P4768)(AC)
已知算法 \***Kruscal重构树**
(1)从1走dijkstra
(2)重构树为小根堆
(3)倍增求对应根
#### 4.[P5022 [NOIP 2018 提高组] 旅行](https://www.luogu.com.cn/problem/P5022)(AC)
n* 暴力dfs
#### 5.[P1155 [NOIP 2008 提高组] 双栈排序](https://www.luogu.com.cn/problem/P1155)
(1)若$a_k<a_i<a_j$ 且 $i<j<k$ 则 $i$、$j$ 不在同一栈中
(2)二分图染色
#### 6.二分图最大匹配(略)(AC)
---
---
## 7.18
### 上午
#### 1.[P1640 [SCOI2010] 连续攻击游戏](https://www.luogu.com.cn/problem/P1640)
已知算法 二分图最大匹配
#### 2.[P2764 最小路径覆盖问题](https://www.luogu.com.cn/problem/P2764)
已知算法 二分图最大匹配
(1)长为1的边建二分图
(2)匹配
#### \*3.[P4589 [TJOI2018] 智力竞赛](https://www.luogu.com.cn/problem/P4589)
#### 4.[P3376 【模板】网络最大流](https://www.luogu.com.cn/problem/P3376)(AC)
已知算法 \***网络流**
(1)双向建边
(2)bfs分层
(3)dfs跑分层图
#### 5.[P2055 [ZJOI2009] 假期的宿舍](https://www.luogu.com.cn/problem/P2055)
已知算法 二分图最大匹配
#### 6.[P1402 酒店之王](https://www.luogu.com.cn/problem/P1402)(AC)
已知算法 网络流跑三分图
#### \*7.[P2762 太空飞行计划问题](https://www.luogu.com.cn/problem/P2762)
### 下午
#### 1.[P1004 [NOIP 2000 提高组] 方格取数](https://www.luogu.com.cn/problem/P1004#ide)&&[P1006 [NOIP 2008 提高组] 传纸条](https://www.luogu.com.cn/problem/P1006#ide)(AC)
#### 2.[P16404 [ECUSTPC 2026 Spring] 海底捞月](https://www.luogu.com.cn/problem/P16404)
#### 3.[P5020 [NOIP 2018 提高组] 货币系统](https://www.luogu.com.cn/problem/P5020)(AC)
#### 4.[P1063 [NOIP 2006 提高组] 能量项链](https://www.luogu.com.cn/problem/P1063)(AC)
#### 5.[P7914 [CSP-S 2021] 括号序列](https://www.luogu.com.cn/problem/P7914)
#### 6.[P2014 [CTSC1997] 选课](https://www.luogu.com.cn/problem/P2014)(AC)
---
---
## 7.19
### 上午
#### 1.[P3478 [POI 2008] STA-Station](https://www.luogu.com.cn/problem/P3478)(AC)
换根dp
#### 2.[CF1187E Tree Painting](https://www.luogu.com.cn/problem/CF1187E)
换根dp(实际上与上题等价)
#### 3.[P1685 游览](https://www.luogu.com.cn/problem/P1685)(AC)
图上dp(dfs+dp)
#### 4.[P13408 [GCJ 2010 Finals] City Tour](https://www.luogu.com.cn/problem/P13408)
dp[e]表示从e(u,v)拓展成的点编号 >max(u,v) 的方案数
#### \*5.[P3647 [APIO2014] 连珠线](https://www.luogu.com.cn/problem/P3647)
dp[i][0/1]表示i为红/蓝点在其子树的方案数
枚举根,O(n)转移
### 下午
#### 1.[P2602 [ZJOI2010] 数字计数](https://www.luogu.com.cn/problem/P2602)(AC)
数位dp(板子)
#### 2.[P2657 [SCOI2009] windy 数](https://www.luogu.com.cn/problem/P2657) && [P13085 [SCOI2009] windy 数(加强版)](https://www.luogu.com.cn/problem/P13085)(AC)
数位dp
#### 3.[P1896 [SCOI2005] 互不侵犯](https://www.luogu.com.cn/problem/P1896)(AC)
状压dp(板子)
#### 4.[P1648 看守](https://www.luogu.com.cn/problem/P1648)(AC)
状压dp
#### 5.[P2704 [NOI2001] 炮兵阵地](https://www.luogu.com.cn/problem/P2704)
状压dp
#### 6.[P1171 售货员的难题](https://www.luogu.com.cn/problem/P1171)(AC)
状压dp
#### \*7.[P8867 [NOIP2022] 建造军营](https://www.luogu.com.cn/problem/P8867)
---
---
## 7.20
### 上午
#### 1.[P8692 [蓝桥杯 2019 国 C] 数正方形](https://www.luogu.com.cn/problem/P8692#ide),但是1e9(AC)
求和推式子
#### 2.[P1641 [SCOI2010] 生成字符串](https://www.luogu.com.cn/problem/P1641)(AC)
卡特兰数
#### 3.[P1450 [HAOI2008] 硬币购物](https://www.luogu.com.cn/problem/P1450)(AC)
完全背包+容斥
#### 4.[P2261 [CQOI2007] 余数求和](https://www.luogu.com.cn/problem/P2261)(AC)
整数划分
#### 5.[P1962 斐波那契数列](https://www.luogu.com.cn/problem/P1962)(AC)
矩阵乘法&&矩阵快速幂
#### 6.[P1192 台阶问题](https://www.luogu.com.cn/problem/P1192),但是1e12(AC)
矩阵乘法&&矩阵快速幂
#### 7.[P1247 取火柴游戏](https://www.luogu.com.cn/problem/P1247)(AC)
博弈论
### 下午
#### 1.[P3951 [NOIP 2017 提高组] 小凯的疑惑](https://www.luogu.com.cn/problem/P3951)(AC)
一维列表,一维查找,最终答案ab-a-b
#### \*2.[P2150 [NOI2015] 寿司晚宴](https://www.luogu.com.cn/problem/P2150)
(1)按大质因数分组
(2)dp转移
#### 3.[P1516 青蛙的约会](https://www.luogu.com.cn/problem/P1516)
#### 4.[P2421 [NOI2002] 荒岛野人](https://www.luogu.com.cn/problem/P2421)
(1)枚举M
(2)$n^2$枚举+扩展欧几里得
#### 5.[P2568 GCD](https://www.luogu.com.cn/problem/P2568)
推式子+欧拉函数
#### \*6.[P3601 签到题](https://www.luogu.com.cn/problem/P3601)
---
---
## 7.21
### 上午
#### 1.[P5664 [CSP-S 2019] Emiya 家今天的饭](https://www.luogu.com.cn/problem/P5664)
dp[i][j][k]表示到i行j菜比其余和多k方案数
#### 2.[P1099 [NOIP 2007 提高组] 树网的核](https://www.luogu.com.cn/problem/P1099)
(1)$n^3$找核
(2)$n^2$找max
#### 3.[P8866 [NOIP2022] 喵了个喵](https://www.luogu.com.cn/problem/P8866)(AC)
15tps思维部分分
85tps分类讨论
#### \*4.[P14636 [NOIP2025] 清仓甩卖](https://www.luogu.com.cn/problem/P14636)
暴力 + A + $(m=2)$=44tps