版本比较
3.27总结
正文
增加 22 行删除 22 行
8 行未改动910111213141516171819202122232425262728293018 行未改动49505152535455565713 行未改动71727374757677787927 行未改动10710810911011111211311411530 行未改动1461471481491501511521531541551561571581591607 行未改动1681691701711721731741751762 行未改动1791801811821831841851861875 行未改动1931941951961971981992002012 行未改动20420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423536 行未改动8 行未改动#define int long longusing namespace std;const int N = 2e6 + 10;int n,head,tail;deque<int>dq;signed main() {cin >> n;for(int i = n;i >= 1;i --) {dq.push_front(i);dq.push_front(dq.back());dq.pop_back();}while(dq.size()) {cout << dq.front() << ' ';dq.pop_front();}return 0;}```# P8641 [蓝桥杯 2016 国 C] 赢球票## Meaning拿出 $N$ 张卡片(上面写着 $1 \sim N$ 的数字),打乱顺序,排成一个圆圈。18 行未改动for(int i = n;i >= 1;i --) {int x;cin >> x;bak.push(x);}int ans = 0;for(int i = 1;i <= n;i ++) {bak.push(bak.front());bak.pop();13 行未改动ans = max(ans,sum);}cout << ans;return 0;}```# P13512 [KOI 2025 #1] 稻草人## Meaning27 行未改动int main() {cin >> N >> P;for (int i = 1; i <= N; i++) cin >> A[i];for (int i = 1; i <= N; i++) {s += A[i];q.push(A[i]);while (q.size() && s - q.top() >= P) {30 行未改动for(int i = 1;i <= n;i ++) {int x;cin >> x;qa.push(x);}for(int i = 1;i <= m;i ++) {int x;cin >> x;qb.push(x);}bool snowane = 0,yuxiao = 0;while(qa.size() && qb.size()) {int x = qa.front();qa.pop();if(vis[x] == 0) {7 行未改动stk.pop();qa.push(y);vis[y] = 0;if(y == x) break;}}if(qa.empty()){cout << "B\n";2 行未改动cout << qb.front() << ' ';qb.pop();}return 0;}x = qb.front();qb.pop();if(vis[x] == 0) stk.push(x), vis[x] = 1;else5 行未改动stk.pop();qb.push(y);vis[y] = 0;if(y == x) break;}}if(qb.empty()){cout << "A\n";2 行未改动cout << qa.front() << ' ';qa.pop();}return 0;}}return 0;}```# P2107 小 Z 的 AK 计划## Meaning小 Z 从家(坐标 $0$)出发,街上依次有 $n$ 个机房,第 $i$ 个机房坐标 $x_i$。移动速度是 $1$,所以从上一个位置到 $x_i$ 需要 $|x_i - x_{prev}|$ 的时间。到达机房后,可以选择花 $t_i$ 的时间“想题”,然后瞬间 AK,也可以直接路过。总时间限制为 $m$,问最多能在多少个机房 AK。## Solution首先,机房在一条直线上,小 Z 肯定只会往一个方向走(因为折返会浪费更多时间),所以我们可以把机房按坐标从小到大排序,然后依次考虑。我们用一个优先队列来维护当前已经决定要 AK 的机房,队列里存的是每个机房的 $t_i$。按顺序处理每个机房 $i$:- 先加上从上一个机房(或家)走到当前机房的移动时间 $x_i - x_{i-1}$($x_0=0$)。- 把这个机房加入候选,总时间加上它的 $t_i$,候选数量加 $1$。- 如果此时总时间超过了 $m$,就说明我们选得太多了,需要去掉一些。因为移动时间已经固定,只能从已经选的机房中踢掉一个最耗时的($t$ 最大的),这样总时间减少得最多,能保留尽可能多的机房。- 从队列里不断弹出最大的 $t$,直到总时间 $\le m$ 为止。如果弹出所有还是超时,那后面的机房也没法再选了,直接结束。这样做下来,每次处理完一个机房后,当前候选数量就是“以当前机房为最远点时能选的最多机房数”,用 $ans$ 记录最大值即可。## Code```cpp36 行未改动8 行未改动910111213141516171819202122232425262728293018 行未改动49505152535455565713 行未改动71727374757677787927 行未改动10710810911011111211311411530 行未改动1461471481491501511521531541551561571581591607 行未改动1681691701711721731741751762 行未改动1791801811821831841851861875 行未改动1931941951961971981992002012 行未改动20420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423536 行未改动8 行未改动#define int long longusing namespace std;const int N = 2e6 + 10;int n,head,tail;deque<int>dq;signed main() {cin >> n;for(int i = n;i >= 1;i --) {dq.push_front(i);dq.push_front(dq.back());dq.pop_back();}while(dq.size()) {cout << dq.front() << ' ';dq.pop_front();}return 0;}```# P8641 [蓝桥杯 2016 国 C] 赢球票## Meaning拿出 $N$ 张卡片(上面写着 $1 \sim N$ 的数字),打乱顺序,排成一个圆圈。18 行未改动for(int i = n;i >= 1;i --) {int x;cin >> x;bak.push(x);}int ans = 0;for(int i = 1;i <= n;i ++) {bak.push(bak.front());bak.pop();13 行未改动ans = max(ans,sum);}cout << ans;return 0;}```# P13512 [KOI 2025 #1] 稻草人## Meaning27 行未改动int main() {cin >> N >> P;for (int i = 1; i <= N; i++) cin >> A[i];for (int i = 1; i <= N; i++) {s += A[i];q.push(A[i]);while (q.size() && s - q.top() >= P) {30 行未改动for(int i = 1;i <= n;i ++) {int x;cin >> x;qa.push(x);}for(int i = 1;i <= m;i ++) {int x;cin >> x;qb.push(x);}bool snowane = 0,yuxiao = 0;while(qa.size() && qb.size()) {int x = qa.front();qa.pop();if(vis[x] == 0) {7 行未改动stk.pop();qa.push(y);vis[y] = 0;if(y == x) break;}}if(qa.empty()){cout << "B\n";2 行未改动cout << qb.front() << ' ';qb.pop();}return 0;}x = qb.front();qb.pop();if(vis[x] == 0) stk.push(x), vis[x] = 1;else5 行未改动stk.pop();qb.push(y);vis[y] = 0;if(y == x) break;}}if(qb.empty()){cout << "A\n";2 行未改动cout << qa.front() << ' ';qa.pop();}return 0;}}return 0;}```# P2107 小 Z 的 AK 计划## Meaning小 Z 从家(坐标 $0$)出发,街上依次有 $n$ 个机房,第 $i$ 个机房坐标 $x_i$。移动速度是 $1$,所以从上一个位置到 $x_i$ 需要 $|x_i - x_{prev}|$ 的时间。到达机房后,可以选择花 $t_i$ 的时间“想题”,然后瞬间 AK,也可以直接路过。总时间限制为 $m$,问最多能在多少个机房 AK。## Solution首先,机房在一条直线上,小 Z 肯定只会往一个方向走(因为折返会浪费更多时间),所以我们可以把机房按坐标从小到大排序,然后依次考虑。我们用一个优先队列来维护当前已经决定要 AK 的机房,队列里存的是每个机房的 $t_i$。按顺序处理每个机房 $i$:- 先加上从上一个机房(或家)走到当前机房的移动时间 $x_i - x_{i-1}$($x_0=0$)。- 把这个机房加入候选,总时间加上它的 $t_i$,候选数量加 $1$。- 如果此时总时间超过了 $m$,就说明我们选得太多了,需要去掉一些。因为移动时间已经固定,只能从已经选的机房中踢掉一个最耗时的($t$ 最大的),这样总时间减少得最多,能保留尽可能多的机房。- 从队列里不断弹出最大的 $t$,直到总时间 $\le m$ 为止。如果弹出所有还是超时,那后面的机房也没法再选了,直接结束。这样做下来,每次处理完一个机房后,当前候选数量就是“以当前机房为最远点时能选的最多机房数”,用 $ans$ 记录最大值即可。## Code```cpp36 行未改动