2023蓝桥杯大学生b组部分题,并且垃圾代码

发布于:2024-04-14 ⋅ 阅读:(160) ⋅ 点赞:(0)

A: 日期统计(5分)
问题描述
小蓝现在有一个长度为100 100100 的数组,数组中的每个元素的值都在0 00 到9 99 的范围之内。数组中的元素从左至右如下所示:

5 6 8 6 9 1 6 1 2 4 9 1 9 8 2 3 6 4 7 7 5 9 5 0 3 8 7 5 8 1 5 8 6 1 8 3 0 3 7 9 2 7 0 5 8 8 5 7 0 9 9 1 9 4 4 6 8 6 3 3 8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4 0 1 0 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3

现在他想要从这个数组中寻找一些满足以下条件的子序列:

子序列的长度为8;
这个子序列可以按照下标顺序组成一个yyyymmdd 格式的日期,并且要求这个日期是2023 年中的某一天的日期,例如20230902,20231223。yyyy 表示年份,mm 表示月份,dd 表示天数,当月份或者天数的长度只有一位时需要一个前导零补充。
请你帮小蓝计算下按上述条件一共能找到多少个不同的2023 年的日期。
对于相同的日期你只需要统计一次即可。

#include "bits/stdc++.h"
#define IOS  ios::sync_with_stdio(0) ,cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int numbers[100] = {5, 6, 8, 6, 9, 1, 6, 1, 2, 4, 9, 1, 9, 8, 2, 3, 6, 4, 7, 7, 5, 9, 5, 0, 3, 8, 7, 5, 8, 1, 5,
                          8, 6, 1, 8, 3, 0, 3, 7, 9, 2, 7, 0, 5, 8, 8, 5, 7, 0, 9, 9, 1, 9, 4, 4, 6, 8, 6, 3, 3, 8, 5,
                          1, 6, 3, 4, 6, 7, 0, 7, 8, 2, 7, 6, 8, 9, 5, 6, 5, 6, 1, 4, 0, 1, 0, 0, 9, 4, 8, 0, 9, 1, 2,
                          8, 5, 0, 2, 5, 3, 3};
const int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(){
    int ans=0;
    for (int i = 1; i <=12; ++i) {
        for (int j = 1; j <=day[i]; ++j) {
            string str="2023";
            if (i<10)
                str+="0";
            str+= to_string(i);
            if (j<10)
                str+="0";
            str+= to_string(j);
            int h=0;
            for (int k=0;k<=99;k++){
                if (numbers[k]==str[h]-'0')
                    h++;
                if (h==8){
                    ans++;
                    break;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

B:01串的熵

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll len=23333333;
double ans=11625907.5798 ;
int fun1(ll num){
    double a=0;
    //ans -= 1.0 * mid * mid / total * log2(1.0 * mid / total);
    a-=1.0 * num * num /len * log2(1.0*num/len);
    a-=1.0 * (len-num) *(len-num)/len * log2(1.0 *(len-num)/len);
    if (abs(a-ans)<1e-4)
        return 1;
    else if (a<ans)
        return 2;//0少了
    else
        return 3;//0多了
}
int main(){
    ll left,right,mid;
    left=0;
    right=23333333/2 +1;
    while(left<right){
        mid=(left+right)/2;
        int t=fun1(mid);
        if (t==1)
            break;
        else if (t==2){
            left=mid+1;
        }
        else if (t==3)
            right=mid;
    }
    cout<<(left+right)/2;
    return 0;
}

这个1.0 很关键

C: 冶炼金属(10分)

#include "bits/stdc++.h"
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
int main(){
    IOS;
    int n;cin>>n;
    ll maxmax=INT32_MAX,maxmin=0;
    ll minmax=INT32_MAX,minmin=0;
    while(n--){
        ll a,b;cin>>a>>b;
        if (maxmax>a/b&&a/b>maxmin)
            maxmax=a/b;
        if (maxmin<a/(b+1))
            maxmin=a/(b+1);
    }
    cout<<maxmin+1<<" "<<maxmax;
    return 0;
}

D:飞机降落

这道题我贪心不能AC,只能过四个测试点:

这是我的贪心代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct plane {
    int T,D,L;
};
bool cmp(plane a,plane b) {
    if(a.T+a.D==b.T+a.D) {
        return a.L<b.L;
    } else
        return a.T+a.D<b.T+b.D;
};
int main() {
    int num;
    cin>>num;
    while(num--) {
        int n;
        cin>>n;
        ll time=0;
        vector<plane> Date;
        for(int i=0; i<n; i++) {
            plane a;
            cin>>a.T>>a.D>>a.L;
            Date.push_back(a);
        }
        int flag=100;
        sort(Date.begin(),Date.end(),cmp);
        for(auto i : Date) {
            if(i.T+i.D<time) {
                flag=-1;
                break;
            }
            if(i.T>time)
                time=i.T;
            time+=i.L;
        }
        if (flag!=-1) {
            cout<<"YES"<<endl;
        }
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

很郁闷

只好看题解了

因为这道题n<10

所以好像暴力破万法

#include<bits/stdc++.h>
using namespace std;
struct plane {
	int T,D,L;
	char vis;
};
typedef long long ll;
plane Date[15];
bool dfs(int step,ll time,int t) {
	if(step==t+1)
		return true;
	for(int i=1; i<=t; i++) {
		if(Date[i].vis==1||time>Date[i].T+Date[i].D)
			continue;
		Date[i].vis=1;
		if(dfs(step+1,max(time,(ll)Date[i].T)+Date[i].L,t)){
			Date[i].vis=0;
			return true;
		}
		Date[i].vis=0;
	}
    return false;
}
int main() {
	int n;
	cin>>n;
	while(n--) {
		memset(Date,0,15);
		ll time=0;
		int t;
		cin>>t;
		for(int i=1; i<=t; i++) {
			cin>>Date[i].T>>Date[i].D>>Date[i].L;
		}//get date
		if(dfs(1,time,t))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

E:接龙数列

#include<bits/stdc++.h>
using namespace std;
vector<int> Date;
int dp[10];
int ans=0;
int len;
int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++){
		string a;
		cin>>a;
		len=a.size();
		int fir=a[0]-'0';
		int las=a[len-1]-'0';
		dp[las]=max(dp[fir]+1,dp[las]);
		ans=max(dp[las],ans);
	}
	cout<<n-ans;
	return 0;
}

岛屿个数:不会,心烦,不写~

F:子串简写

写不来,暴力!凸(艹皿艹 ),反正oi赛制,

#include<bits/stdc++.h>
using namespace std;
int main(){
    std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int k;cin>>k;
    string str;cin>>str;
    char a,b;cin>>a>>b;
    int ans=0;
    for(int i=0;i<str.size();i++){
        if(str[i]==a){
            for(int j=i+k-1;j<str.size();j++){
                if(str[j]==b)
                    ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}

这样可以得这道题的24分


网站公告

今日签到

点亮在社区的每一天
去签到