版本比较
1023 训练课 错题集 黄梓涵
正文
增加 87 行删除 6 行
142 行未改动全部展开143144145146147148149150151152153154155142 行未改动全部展开|👊|👊|✌| **A、B**||👊|✌|✌|**A**||✋|👊|👊|**A**||✌|✋|✋|**A**||👊|✌|✌|**B**||✋|👊|👊|**B**||✌|✋|✋|**B**||👊|✌|✌|**C**||✋|👊|👊|**C**||✌|✋|✋|**C**||方案总计:$18$|<|<|<|::::然后写 $18$ 个 `if` 即可AC142 行未改动全部展开143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236142 行未改动全部展开|👊|👊|✌| **A、B**||👊|✌|✌|**A**||✋|👊|👊|**A**||✌|✋|✋|**A**||✌|👊|✌|**B**||👊|✋|👊|**B**||✋|✌|✋|**B**||✌|✌|👊|**C**||👊|👊|✋|**C**||✋|✋|✌|**C**||方案总计:$18$|<|<|<|::::然后写 $18$ 个 `if` 即可AC## [D46879 月色的花园绿化](https://gonoi.com.cn/problem/D46879 "T3")### ⌨ 完整代码```cpp#include<bits/stdc++.h>using namespace std;priority_queue<int,vector<int>,greater<int> >q;int main() {ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);int Q;cin>>Q;while(Q--){int op,h;cin>>op>>h;if(op==1){q.push(h);cout << q.size() << "\n";}else{while(q.size()!=0&&q.top()<=h){q.pop();}cout << q.size() << "\n";}}return 0;}```### 🧠思路问题```cpppriority_queue<int,vector<int>,greater<int> >q;```优先队列-小根堆,小的优先在最前面对于操作 $1$ ,直接插入 $h$对于操作 $2$ ,只要当队头比给出的 $h$ 小就删但是!如果删干净了,会RE,我们需要优先判断队空## [D46876 字符替换](https://gonoi.com.cn/problem/D46876 "T4")### ⌨ 完整代码```cpp#include<bits/stdc++.h>using namespace std;int main() {int m,ans=INT_MAX;cin>>m>>m;string s;cin>>s;for(char c='a';c<='z';c++){int cnt=0;for(int i=0;i<s.size();i++){if(s[i]!=c){i+=m;i--;cnt++;}}ans=min(ans,cnt);}cout << ans;return 0;}```### 🧠思路问题暴力题 ~~(小心暴力的时候用力过猛把地球挖穿去阿根廷了)~~枚举每一个可以替代的字符,代码中展示为所有小写字母,每次循环遍历整个字符串,若当前字符和替代字符不是相同的,则下标增加 $m-1$ 个,然后 $cnt+1$ ,最后每一个 $cnt$ 打擂台