正文
增加 13 行删除 9 行
28 行未改动29303132333435363757 行未改动959697989910010110210367 行未改动17117217317417517617717817953 行未改动2332342352362372382392402412422432442452462472488 行未改动25725825926026126226326426511 行未改动27727827928028128228328428528628712 行未改动28 行未改动## 时间复杂度因为我们要求 `gcd`,所以最终复杂度 $O(\log_2 n)$。## AC Code:```cpp#include<bits/stdc++.h>using namespace std;57 行未改动由于我们直接取的公式,单次计算复杂度均为 $O(1)$。数据组数为 $T$,则总复杂度为 $O(T)$。## AC Code:```#include<bits/stdc++.h>using namespace std;67 行未改动我们需要进行 `map<pair<int,int>,int>` 来存储边,且统计时我们还需进行排序,所以单次复杂度 $O(\log_2 n)$。因为我们的算法基底复杂度为 $O(n)$,故总时间复杂度为 $O(n\log_2n)$。## AC Code:```#include<bits/stdc++.h>using namespace std;53 行未改动# D. Wind-Ball 题解## 题面及思路## 时间复杂度## AC Code:```#include<bits/stdc++.h>#define int long longusing namespace std;8 行未改动inline bool check(int mid){for ( int i = mid; i <= m; i ++){if (s[i] - s[i - mid] < 2 * k) return false;}return true;}signed main(){ios::sync_with_stdio(0);11 行未改动while (l <= r){mid = (l + r) >> 1;if (check(mid)){r = mid - 1;}else l = mid + 1;}int ans = r + 1;sort(p + 1,p + n + 1,cmp);l = 1,r = n;while (l <= r){12 行未改动28 行未改动29303132333435363757 行未改动959697989910010110210367 行未改动17117217317417517617717817953 行未改动2332342352362372382392402412422432442452462472482492502512528 行未改动26126226326426526626726826911 行未改动28128228328428528628728828929029112 行未改动28 行未改动## 时间复杂度因为我们要求 `gcd`,所以最终复杂度 $O(\log_2 n)$。## AC Code:```cpp#include<bits/stdc++.h>using namespace std;57 行未改动由于我们直接取的公式,单次计算复杂度均为 $O(1)$。数据组数为 $T$,则总复杂度为 $O(T)$。## AC Code:```#include<bits/stdc++.h>using namespace std;67 行未改动我们需要进行 `map<pair<int,int>,int>` 来存储边,且统计时我们还需进行排序,所以单次复杂度 $O(\log_2 n)$。因为我们的算法基底复杂度为 $O(n)$,故总时间复杂度为 $O(n\log_2n)$。## AC Code:```#include<bits/stdc++.h>using namespace std;53 行未改动# D. Wind-Ball 题解## 题面及思路我们设 $k$ 为小球跳跃能力。若 $k$ 无法完成任务则 $k - 1$ 亦无法完成;若 $k$ 可以完成任务则 $k + 1$ 亦可以完成。故答案具有**单调性**,考虑二分答案。小球做 $x$ 组折返,所以一个点要经过 $2x$ 次。而当跳跃能力为 $k$ 时,我们一次最多跳 $k$ 长度,所以可以发现每个长度为 $k$ 的区间,浮冰承受力总和不得小于 $2x$。我们依据这点来写 `check()` 函数。我们在读入之后,将能力进行排序,在排序后的数组中查找能满足条件的最小值,若能查到输出编号;当 $l=n+1$ 时,则无解。若仍不懂见 [P8775 青蛙过河](https://www.luogu.com.cn/problem/P8775)。## 时间复杂度二分答案和排序时间复杂度均为 $O(n\log_2n)$,很好理解,不做解释。## AC Code:```#include<bits/stdc++.h>#define int long longusing namespace std;8 行未改动inline bool check(int mid){for ( int i = mid; i <= m; i ++){if (s[i] - s[i - mid] < 2 * k) return false;}return true;}signed main(){ios::sync_with_stdio(0);11 行未改动while (l <= r){mid = (l + r) >> 1;if (check(mid)){r = mid - 1;}else l = mid + 1;}int ans = r + 1;sort(p + 1,p + n + 1,cmp);l = 1,r = n;while (l <= r){12 行未改动