山东csp-x2022 试题及讲解视频

山东csp-x2022 试题

T319766 独木桥(bridge)山东csp-x2022第一题 https://www.luogu.com.cn/problem/T319766
T319768移动棋子(chess)山东csp-x2022第二题 https://www.luogu.com.cn/problem/T319768
T319769 动物园(zoo)山东csp-x2022第三题 https://www.luogu.com.cn/problem/T319769
T319770 摧毁(destroy)山东csp-x2022第四题 https://www.luogu.com.cn/problem/T319770

T319766 独木桥(bridge)山东csp-x2022第一题

题目地址:https://www.luogu.com.cn/problem/T319766

题目讲解:https://www.bilibili.com/video/BV1YY41167a3/?spm_id_from=333.999.0.0&vd_source=fa5102b0272af775d3bc4ab69fc72737

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 const int N=1000010;
 5 int n,l,a[N];
 6 int mmax=0;
 7 int main() {
 8     scanf("%d %d",&n,&l);
 9     for(int i=1; i<=n; i++) {
10         scanf("%d",&a[i]);
11         int t=min(a[i],l-a[i]);
12         mmax=max(t,mmax);
13     }
14     printf("%d",mmax);
15     return 0;
16 }

 T319768移动棋子(chess)山东csp-x2022第二题

题目地址:https://www.luogu.com.cn/problem/T319768

题目讲解:https://www.bilibili.com/video/BV1DY4y1C7vd/?vd_source=fa5102b0272af775d3bc4ab69fc72737

#include<iostream>
#include<cmath>
using namespace std;
int x,y;
int ans=1000000001;
int main() {
    cin>>x>>y;
    if(x<=y) { //x可以直接右移到y
        ans=min(ans,y-x);
    }
    if(x<=-y) { //x可以右移到-y,然后变为y
        ans=min(ans,-y-x+1);
    }
    if(-x<=y) { //x可以变为-x,右移到y
        ans=min(ans,y-(0-x)+1);
    }
    if(-y>=-x) {//x可以变为-x,右移到-y,再变为-x
        ans=min(ans,-y-(-x)+2);
    }
    cout<<ans;
    return 0;
}

 T319769 动物园(zoo)山东csp-x2022第三题 

题目链接:https://www.luogu.com.cn/problem/T319769

题目讲解:https://www.bilibili.com/video/BV1a84y1P7zt/?vd_source=fa5102b0272af775d3bc4ab69fc72737

#include<iostream>
#include<cmath>
using namespace std;
const int N=1000010;
const int M=2010;
int n,m;
int l=1;//左端点
int cot=0;//l到i之间动物的种类
int a[N];//ai保存i号场馆存放了什么动物
int b[M];//保存l到i之间每种动物出现的次数
int main() {
    scanf("%d %d",&n,&m);
    int ans=n;
    for(int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        if(b[a[i]]==0) cot++;
        b[a[i]]++;
        if(cot==m) { //l右移
            for(int j=l; j<=i; j++) {
                if(b[a[j]]>1) {
                    l++;
                    b[a[j]]--;
                }
                else break;
            }
            ans=min(ans,i-l+1);
        }
    }
    printf("%d",ans*10);
    return 0;
}

 T319770 摧毁(destroy)山东csp-x2022第四题 

题目链接:https://www.luogu.com.cn/problem/T319770

题目讲解:https://www.bilibili.com/video/BV1Ug4y1t7or/?vd_source=fa5102b0272af775d3bc4ab69fc72737

#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const int N=1000010;
int t,n,c;
int num[N];
int main() {
    scanf("%d",&t);
    while(t--) {
        int k,mmin=N,mmax=0;
        scanf("%d %d",&n,&c);
        memset(num,0,sizeof(num));
        for(int i=1; i<=n; i++) {
            scanf("%d",&k);
            num[k]++;
            mmin=min(mmin,k);
            mmax=max(mmax,k);
        }
        int ans=0;
        for(int i=mmin; i<=mmax; i++) {
            if(num[i]>=c) ans+=c;
            else ans+=num[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}
posted @ 2023-03-07 12:51  关于42号星球  阅读(2895)  评论(0编辑  收藏  举报