标题
增加 1 行删除 1 行
19.18-甜菜测试-410-课堂总结110.9-甜菜测试-410-课堂总结
正文
增加 144 行删除 112 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168# 9.18-甜菜测试-410-课堂总结## T3 T819625 月色的快乐路径### [题目传送门](https://www.luogu.com.cn/problem/T819625 "T819625 月色的快乐路径")::::info[考察知识点]{open}* DFS模拟::::❌️${\color{red}错误原因:}$- 细节处理错误❌️${\color{red}错误思路:}$- 从起点到终点的每一种路线都用 DFS 去走一遍求出所有满足条件的路线,计算数量,输出❌️${\color{red} 错误代码(}{\color{red}Unaccepted\ \ 4分}\color{red}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;int a[15][15],f,n,m;long long sum=0;map<int,int>s;int d[2][2]={{1,0},{0,1}};void ff(int x,int y){if(x==n&&y==m){s[a[x][y]]=0;if(f==0)sum++;f=0;return;}for(int i=0;i<2;i++){int dx=x+d[i][0],dy=y+d[i][1];if(dx<=n&&dx>=1&&dy<=m&&dy>=1){if(s[a[dx][dy]]==1){f=1;s[a[dx][dy]]=1;}else if(f==0){ff(dx,dy);s[a[dx][dy]]=1;}}}s[a[x][y]]=0;}int main(){cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}ff(1,1);cout<<sum;return 0;}```✅️${\color{green}正确思路:}$* 从起点到终点的每一种路线都用 DFS 去走一遍求出所有满足条件的路线,计算数量,输出✅️${\color{green} 正确代码(}{\color{green}Accepted\ \ 100分}\color{green}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;int a[15][15],n,m;long long sum=0;map<int,int>s;int d[2][2]={{1,0},{0,1}};//方向数组void f(int x,int y){//DFSs[a[x][y]]=1;if(x==n&&y==m){s[a[x][y]]=0;sum++;return;}for(int i=0;i<2;i++){int dx=x+d[i][0],dy=y+d[i][1];if(dx<=n&&dx>=1&&dy<=m&&dy>=1){//没有越界if(s[a[dx][dy]]==0){//下一步的数值没有被走过f(dx,dy);}}}s[a[x][y]]=0;//记得回溯}int main(){cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}f(1,1);cout<<sum;return 0;}```## T4 P17459 [GESP202609 七级] 必经之路### [题目传送门](https://www.luogu.com.cn/problem/P17459 "P17459 [GESP202609 七级] 必经之路")::::info[考察知识点]{open}* 图论,超级源点,超级汇点::::❌️${\color{red}错误原因:}$- 骗分❌️${\color{red}错误思路:}$- 骗分❌️${\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 0分}\color{red}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;int main(){cout<<"2\n4 5";return 0;}```✅️${\color{green}正确思路:}$* 必经点去掉之后所有合法起点到所有合法终点就没法走了,所以我们可以把每一个点都去掉一次,如果去掉了就不能走了,那么那个点就是必经点✅️${\color{green} 正确代码(}{\color{green} 100分}\color{green}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;vector<int>a[1005];int cnt1[1005],cnt2[1005],vis[1005],n,m;void dfs(int x){vis[x]=1;for(auto i:a[x]){if(vis[i]==0){vis[i]=1;dfs(i);}}}int main(){cin>>n>>m;while(m--){int x,y;cin>>x>>y;a[x].push_back(y);cnt1[y]++;cnt2[x]++;}for(int i=1;i<=n;i++){if(cnt1[i]==0){//判断合法起点a[0].push_back(i);//所有合法起点都从一个点出来更快}if(cnt2[i]==0){判断合法终点a[i].push_back(n+1);//所有合法终点都到一个点更快}}vector<int>ans;for(int i=1;i<=n;i++){memset(vis,0,sizeof vis);//注意要还原标记vis[i]=1;//标记了就不能走了,就相当于去掉这个点dfs(0);if(vis[n+1]==0){//不能到终点,是必经点ans.push_back(i);}}cout<<ans.size()<<"\n";for(int i=0;i<ans.size();i++){cout<<ans[i]<<" ";}return 0;}```~~这篇文章很水~~123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200# 10.9-甜菜测试-410-课堂总结## T2 P17554 「WWOI R4」二五一十### [题目传送门](https://www.luogu.com.cn/problem/P17554 "P17554 「WWOI R4」二五一十")::::info[考察知识点]{open}* Idon't know.::::❌️${\color{red}错误原因:}$- 骗分❌️${\color{red}错误思路:}$- 骗分❌️${\color{red} 错误代码(}{\color{red}Unaccepted\ \ 0分}\color{red}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;#define int long longint a[35][35],vis[5];signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin>>n;while(n--){string c;cin>>c;for(int i=c.size()-1;i>=0;i--){if(c[i]!='0'){cout<<i+1<<'\n';break;}}}return 0;}```✅️${\color{green}正确思路:}$* 我们可以发现如果一个数乘5,如果原来的数是2的倍数,那么它去掉末尾的所有0所得到的数等于原数除以2,同理,如果一个数乘2,如果原来的数是5的倍数,那么它去掉末尾的所有0所得到的数等于原数除以5,所以一个数如果是2的倍数,那么它就一直乘5直到不是2的倍数,所以一个数如果是5的倍数,那么它就一直乘2直到不是5的倍数,最后算出的数的有效长度一定是最小的✅️${\color{green} 正确代码(}{\color{green}Accepted\ \ 100分}\color{green}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;#define int long longsigned main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int m;cin>>m;while(m--){int n;cin>>n;while(n%2==0)n/=2;//实际操作要用除法,防止溢出while(n%5==0)n/=5;//同理int a=0;while(n){//求有效长度n/=10;a++;}cout<<a<<'\n';}return 0;}```## T3 P17590 Xterfusion### [题目传送门](https://www.luogu.com.cn/problem/P17590 "P17590 Xterfusion")::::info[考察知识点]{open}* 线性DP::::❌️${\color{red}错误原因:}$- 骗分❌️${\color{red}错误思路:}$- 骗分❌️${\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 10分}\color{red}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;#define int long longint a[35][35],vis[5];signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin>>n;cout<<n;return 0;}```✅️${\color{green}正确思路:}$* 枚举一个数学,先正向做一遍每个位置相差2x的子序列的DP,让dp1[i]代表以位置i为结尾的子序列的最大长度,再反向做一遍每个位置相差x的子序列的DP,让dp[i]代表以位置i为开头的子序列的最大长度,最后把它们拼起来,求出最大长度,输出✅️${\color{green} 正确代码(}{\color{green} 100分}\color{green}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;#define int long longint dp[1010],dp1[1010];signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n;cin>>n;string s;cin>>s;s="#"+s;int ans=0;for(int x=1;x<=n;x++){for(int i=1;i<=n;i++){if(i>=2*x&&s[i]=='X')dp1[i]=dp1[i-2*x]+1;//如果当前位置不为"."计算以i为结尾的最大长度else if(s[i]=='X')dp1[i]=1;//如果为"."以当前位置为结尾的最大长度为1}for(int i=n;i>=1;i--){if(i+x<=n&&s[i]=='X')dp[i]=dp[i+x]+1;/如果当前位置不为"."计算以i为结尾的最大长度else if(s[i]=='X')dp[i]=1;//如果为"."以当前位置为结尾的最大长度为1}for(int i=1;i<=n;i++){//枚举拼接点ans=max(ans,dp1[i]+dp[i]-1);//计算最长“好的”子序列的最大长度}}cout<<ans;return 0;}```## T4 B4568 [山东省小学组体验营 2026] 中位数### [题目传送门](https://www.luogu.com.cn/problem/B4568 "B4568 [山东省小学组体验营 2026] 中位数")::::info[考察知识点]{open}* 双指针,二分答案::::❌️${\color{red}错误原因:}$- 骗分❌️${\color{red}错误思路:}$- 骗分❌️${\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 10分}\color{red}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;#define int long longint a[35][35],vis[5];signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,m;cin>>n>>m;cout<<m;return 0;}```✅️${\color{green}正确思路:}$* 这道题可以将一个数组做某些操作,让中位数更大,我们可以将所得到的数组排序,然后这道题就变成了找到一个数x,至少得有一半及以上的数比x大,使x尽可能的大,这个操作用双指针做,r为当前分配给a[l]的下标,然后我们会发现x小的时候肯定是可以让至少得有一半及以上的数比x大,随着x越来越大,最后就不能让至少得有一半及以上的数比x大,所以我们可以用二分答案来找右边界,也就是最大的x,输出✅️${\color{green} 正确代码(}{\color{green} 100分}\color{green}):$```c++ line-numbers#include<bits/stdc++.h>using namespace std;#define int long longint a[100010],n;int check(int x){int cnt=0;int l=1,r=1;while(l<=n){//双指针if(a[l]-x>=r){//当前位置的数可以分配到一个下标也大于xl++;r++;cnt++;}else l++;}return cnt*2>n;//至少得有一半及以上的数比x大,但是cnt>n/2不好算,所以算cnt*2>n}signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+n+1);int l=-2e9,r=2e9;while(l+1<r){//二分答案寻找右边界,也就是最大的xint mid=(l+r)>>1;if(check(mid))l=mid;else r=mid;}cout<<l;return 0;}```~~这篇文章很水~~