跳到正文

个人记录

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

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

文章信息

发布
2026年11月19日
收录
2026年11月19日
更新
2026年11月21日
篇幅
约 7 分钟

版本

  1. v1当前

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

T2 P17837 解密

考察知识点
  • 暴力枚举

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

  • 骗分

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

  • 骗分

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

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);
	cout<<"-1";
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 暴力枚举每一个密码,如果符合给出的所有条件,就是一个正确密码

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

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
string a[105];
int b[105];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }
    int x=0;
    for(int i=0;i<=9999;i++){//暴力枚举
        x=i;
        string s;//处理前导0
        if(x<10){
            s="000";
        }
        else if(x<100){
            s="00";
        }
        else if(x<1000){
            s='0';
        }//处理前导0
        s+=to_string(x);
        int xxx=0;
        for(int j=1;j<=n;j++){//判断是否符合所有条件
            int xx=0;
            for(int ii=0;ii<4;ii++){
                if(a[j][ii]==s[ii])xx++;
            }
            if(xx==b[j])xxx++;
        }
        if(xxx==n){//符合所有条件,输出
            cout<<s;
            return 0;
        }
    }
    cout<<-1;
	return 0;
}

T3 P17770 物资准备

考察知识点
  • I don′t know.I\ don't\ know.

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

  • 暴力

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

  • 暴力

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

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[200005],b[2000005];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	if(n>30000){
		int sum,f=0;
		int aa,ab;
		while(n--){
			cin>>aa>>ab;
			if(sum+aa>=ab)f=1;
			else sum+=aa;
		}
		if(f==1)cout<<ab;
		else cout<<sum;
	}
	else{
		for(int i=1;i<=n;i++){
			cin>>a[i]>>b[i];
		}
		int sum=LONG_LONG_MIN;
		for(int i=0;i<=n;i++){
			int x=0;
			for(int j=1;j<=n;j++){
				if(j==i)continue;
				x+=a[j];
				x=min(b[j],x);
			}
			if(i>0){
				x+=a[i];
				x=min(b[i],x);
			}
			sum=max(x,sum);
		}
		cout<<sum;
	}
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 很简单,用前缀和来算移动的前一部分,而后一部分每一次的限制等于从后往前的前一个毫无限制的值加上当前的限制(也就是可能得最大值)和上一次的限制求最小值,最后枚举移动点位,算出答案,输出

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

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[200005],b[2000005],sum[200005],ans[200005],c[200005];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
    for(int i=1;i<=n;i++){//前一部分,前缀和
        cin>>a[i]>>b[i];
        sum[i]=min(b[i],sum[i-1]+a[i]);
    }
    c[n+1]=1E18;
    for(int i=n;i>=1;i--){//后一部分
        ans[i]=ans[i+1]+a[i];//毫无限制的值
        c[i]=min(ans[i+1]+b[i],c[i+1]);//最大限制
    }
    int cnt=sum[n];
    for(int i=1;i<=n;i++){
        cnt=max(cnt,min(min(sum[i-1]+ans[i+1],c[i+1])+a[i],b[i]));//计算答案
    }
    cout<<cnt;
	return 0;
}

T4 P14338 [JOI2020 预选赛 R2] 十键键盘 / Tenkey

考察知识点
  • I don’t know.

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

  • 骗分

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

  • 骗分

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

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[200005],b[2000005];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout<<5;
	return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 空

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

C++
//空

这篇文章很水

原文