版本比较
雅礼兴趣小组总结-3
正文
增加 141 行删除 0 行
603 行未改动全部展开60460560660760860961061158 行未改动67067167267367467567667761 行未改动603 行未改动全部展开}//```:::### [The Delivery Dilemma](https://codeforces.com/problemset/problem/1443/C)#### 题意求出$\min(\max其他外卖员的,剩余的和)$#### 知识点58 行未改动return 0;}```:::### [Palindrome Basis](codeforces.com/problemset/problem/1673/C)#### 题意求$Q$个数$n$能分成几种回文数的和#### 知识点61 行未改动603 行未改动全部展开60460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866958 行未改动72872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781861 行未改动603 行未改动全部展开}//```:::### [Building a Fence](https://codeforces.com/problemset/problem/1469/C)#### 题意求是否存在一种情况将东西放到当前高度及$+k-1$处,且相邻的要有接触#### 知识点思想#### 正解求出当前可以放在哪里,记录成$l \sim r$,再看$l>r$就说明不可能,最后的$h[n]要在l \sim r内$#### 错因没有做#### 心得每道题都要做到#### 复杂度* 时间复杂度:$O(N)$* 空间复杂度:$O(N)$:::success[代码]{open}```cpp#include <bits/stdc++.h>#define int long longusing namespace std;int h[200005];signed main ( ){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int Q;cin >> Q;while (Q--){int n , k;cin >> n >> k;for (int i=1;i<=n;i++){cin >> h[i];}bool p=1;int l=h[1] , r=h[1];for (int i=2;i<=n;i++){l=max (l-k+1 , h[i]);r=min (r+k-1 , h[i]+k-1);if (l>r){p=0;break;}}if (h[n]<l||h[n]>r){p=0;}if (p==0) cout << "NO\n";else cout << "YES\n";}return 0;}```:::### [The Delivery Dilemma](https://codeforces.com/problemset/problem/1443/C)#### 题意求出$\min(\max其他外卖员的,剩余的和)$#### 知识点58 行未改动return 0;}```:::### [Infected Tree](codeforces.com/problemset/problem/1689/C)#### 题意病毒会传染给和它相连的点,每次你可以拯救一个未被感染的点,切除,它的子树的点成功,求最后最多有多少个成功的点#### 知识点树形$dp$#### 正解先用$dfs$求出每个点的儿子和子树中的点的数量,再用树形$dp$,$dp[i]$表示$i$被感染后最多能成功几个点,输出$dp[1]$#### 错因没想到#### 心得$???$#### 复杂度* 时间复杂度:$O(N)$* 空间复杂度:$O(N)$:::success[代码]{open}```cpp#include <bits/stdc++.h>using namespace std;vector <int> g[300005];int son[2][300005];int dp[300005] , sz[300005];int Q , n , u , v;void dfs (int now , int lst){sz[now]=1;int cnt=-1;for (auto i:g[now]){if (i==lst) continue;cnt++;son[cnt][now]=i;dfs (i , now);sz[now]+=sz[i];}}void DFS (int now , int lst){for (auto i:g[now]){if (i==lst) continue;DFS (i , now);}int x=son[0][now] , y=son[1][now];if (x>0&&y==0){dp[now]=sz[x]-1;}else if (y>0){dp[now]=max (dp[x]+sz[y]-1 , sz[x]-1+dp[y]);}}int main ( ){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> Q;while (Q--){cin >> n;for (int i=1;i<=n;i++){son[0][i]=0;son[1][i]=0;dp[i]=0;sz[i]=0;g[i].clear ( );}for (int i=1;i<=n-1;i++){cin >> u >> v;g[u].push_back (v);g[v].push_back (u);}dfs (1 , 0);DFS (1 , 0);cout << dp[1] << "\n";}return 0;}```:::### [Palindrome Basis](codeforces.com/problemset/problem/1673/C)#### 题意求$Q$个数$n$能分成几种回文数的和#### 知识点61 行未改动