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

· · 个人记录

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

T2 P17554 「WWOI R4」二五一十

题目传送门

::::info[考察知识点]{open}

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

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

#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}正确思路:}

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

#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

题目传送门

::::info[考察知识点]{open}

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

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

#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}正确思路:}

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

#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] 中位数

题目传送门

::::info[考察知识点]{open}

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

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

#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}正确思路:}

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

#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;
}

这篇文章很水