跳到正文

个人记录

10.9-甜菜测试-410-课堂总结

Yuese_约 9 分钟
原文
文章信息与版本

文章信息

发布
2026年9月18日
收录
2026年9月18日
更新
2026年11月14日
篇幅
约 9 分钟

版本

  1. v3当前
  2. v2
  3. v1

10.9-甜菜测试-410-课堂总结

T2 P17554 「WWOI R4」二五一十

题目传送门

考察知识点
  • Idon’t know.

❌️错误原因:{\color{red}错误原因:}

  • 骗分

❌️错误思路:{\color{red}错误思路:}

  • 骗分

❌️错误代码(Unaccepted  0分):{\color{red} 错误代码(}{\color{red}Unaccepted\ \ 0分 }\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int 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的倍数,最后算出的数的有效长度一定是最小的

✅️正确代码(Accepted  100分):{\color{green} 正确代码(}{\color{green} Accepted\ \ 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed 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

题目传送门

考察知识点
  • 线性DP

❌️错误原因:{\color{red}错误原因:}

  • 骗分

❌️错误思路:{\color{red}错误思路:}

  • 骗分

❌️错误代码(Unaccepted  10分):{\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 10分}\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int 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为开头的子序列的最大长度,最后把它们拼起来,求出最大长度,输出

✅️正确代码(100分):{\color{green} 正确代码(}{\color{green} 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int 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] 中位数

题目传送门

考察知识点
  • 双指针,二分答案

❌️错误原因:{\color{red}错误原因:}

  • 骗分

❌️错误思路:{\color{red}错误思路:}

  • 骗分

❌️错误代码(Unaccepted  10分):{\color{red} 错误代码(}{\color{Red} Unaccepted\ \ 10分}\color{red}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int 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,输出

✅️正确代码(100分):{\color{green} 正确代码(}{\color{green} 100分}\color{green}):

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100010],n;
int check(int x){
    int cnt=0;
    int l=1,r=1;
    while(l<=n){//双指针
        if(a[l]-x>=r){//当前位置的数可以分配到一个下标也大于x
            l++;
            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){//二分答案寻找右边界,也就是最大的x
        int mid=(l+r)>>1;
        if(check(mid))l=mid;
        else r=mid;
    }
    cout<<l;
	return 0;
}

这篇文章很水

原文