版本比较
2026-7-18 雅礼比赛总结
正文
增加 153 行删除 9 行
11 行未改动12131415161617181920120 行未改动全部展开141142143144145145146147148149222 行未改动全部展开37237337437537637637737837938038137837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753840140253954054154254354454554654754854955055155255355455555611 行未改动## 三、题目复盘(按题目难度排序)
### T1:$\texttt{Herdle}$
- **本题得分:$\color{green} 90$**- **本题得分:$\color{green} 91$**- **开始时间:$\texttt{8:30}$**- **结束时间:$\texttt{9:10}$**- **总用时:$\texttt{40}$ 分钟**
120 行未改动全部展开#### 本题总结
### T2:$\texttt{Non-Transitive Dice}$
- **本题得分:$0$**- **本题得分:$10$**- **开始时间:无**- **结束时间:无**- **总用时:无**
222 行未改动全部展开```
#### 本题总结
### T4:### T4:$\texttt{Flowerpot S}$
- **本题得分:**- **开始时间:**- **结束时间:**- **总用时:**- **本题得分:$\color{yellow} 40$**- **开始时间:$\texttt{10:15}$**- **结束时间:$\texttt{10:55}$**- **总用时:$40$ 分钟**
#### 初始思路
因为花盆的宽度是单调不减的,所以可以使用二分答案。那二分答案的上界是多少呢?容易想到,花盆的初始坐标不可能摆到 $x$ 坐标大于 $\displaystyle \max_{i = 1}^{n} x_i$ 的地方,因为那里不可能有水,也不可能有解。然后下界就是 $0$。
然后,在二分里每次检查一个 `mid`,暴力枚举花盆的初始坐标和可以被花盆接到的水,算出最高和最低的 $y$。那为什么不是时间呢?因为每过一个时间单位,水的 $y$ 坐标就会减少 $1$,所以我们可以把 $y$ 坐标看成时间。这样,就能减少很多计算。
最后,答案就是 $r$。至于**无解**,因为 `r = 0`,所以当检查一直无效时,`r` 最终会到 $0 - 1$ 的地方,也就是 $-1$。所以这里我们无需重复判断无解。
#### 考场解题过程
同上。
#### 考场代码
```cpp line-numbers#include <iostream>#include <cstdio>using namespace std;
#define CLOSE_FREOPEN
struct Coord{ int x; int y;};
const int N = 1e5 + 10;Coord pos[N];
int n,d,maxn = 0;bool check(int len){ for(int x = 0;x + len <= maxn;x++){ int mintime = 1e9,maxtime = 0; for(int i = 1;i <= n;i++){ if(pos[i].x >= x && pos[i].x <= x + len){ mintime = min(mintime,pos[i].y); maxtime = max(maxtime,pos[i].y); } } if(maxtime - mintime >= d){ return true; } } return false;}
int main(){ #ifndef CLOSE_FREOPEN freopen("fpot.in","r",stdin); freopen("fpot.out","w",stdout); #endif cin >> n >> d; for(int i = 1;i <= n;i++){ cin >> pos[i].x >> pos[i].y; maxn = max(maxn,pos[i].x); } int l = 0,r = maxn; while(l < r){ int mid = (l + r) >> 1; if(check(mid)) r = mid; else l = mid + 1; } cout << r << ' ';
return 0;}
```
#### 赛后题解
大体框架和上面相同,只是在检查的时候用队列优化了,使得时间复杂度从原本的 $\displaystyle O(n \times \max_{i = 1}^{n})$ 降至了 $O(n)$。
#### 补题代码
```cpp line-numbers#include <iostream>#include <deque>#include <algorithm>using namespace std;
struct Node{ int x,y;};
const int N = 1e5 + 10;Node a[N];
bool cmp(Node x,Node y){ return x.x < y.x;}
int n,d;bool check(int x){ deque<int> q1,q2; for(int i = 1;i <= n;i++){ while(!q1.empty() && a[i].y > a[q1.back()].y){ q1.pop_back(); } q1.push_back(i); while(a[i].x - a[q1.front()].x > x){ q1.pop_front(); } while(!q2.empty() && a[i].y < a[q2.back()].y){ q2.pop_back(); } q2.push_back(i); while(a[i].x - a[q2.front()].x > x){ q2.pop_front(); } if(a[q1.front()].y - a[q2.front()].y >= d){ return true; } } return false;}int main() { // freopen("fpot.in","r",stdin); // freopen("fpot.out","w",stdout); cin >> n >> d; for(int i = 1;i <= n;i++){ cin >> a[i].x >> a[i].y; } sort(a + 1,a + n + 1,cmp); int l = -1,r = 1e6 + 1; while(l + 1 < r){ int mid = (l + r) >> 1; if(check(mid)){ r = mid; } else{ l = mid; } } cout << (r > 1e6 ? -1 : r); return 0 ;}```
#### 复杂度
- 时间复杂度:- 空间复杂度:- 时间复杂度:$O(n \times \log 10^6)$- 空间复杂度:$O(n)$
#### 本题总结
## 四、整体反思
### 做得较好的地方
每道题都拿了分,没有浪费时间。
### 需要改进的地方
思维能力还需要加强一下。
### 时间安排总结
见上方比赛总体总结。