跳到正文

个人记录

8.7总结

yudazhou约 4 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

一、比赛基本情况

比赛日期: 8.7

比赛时长: 2h

比赛得分: 330pts

比赛排名:1

二、比赛整体回顾

做题顺序:T1-T2-T3-T4

时间安排:

T1:45min

T2:55min

T3:15min

T4:5min

比赛状态:Very good!

整体感受:感觉都很简单

三、题目复盘

B4516 [四川青少年 C++ 算法设计大赛 2025] 醒来的统计

本题得分: 30pts

开始时间: 15:55

结束时间: 16:00

总用时:5min

初始思路:

先二分一下 nn ,然后check里面写数位dp,统计 xx 的个数,最后输出 ltlt 即可。

考场解题过程:

由于没时间了,所以只打了个暴力。 3030 pts

考场代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=2000020;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x,y;
	cin>>x>>y;
	int i=0;
	int ans=0;
	while(1)
	{
		i++;
		int t=i;
		while(t!=0)
		{
			if(t%10==x)ans++;
			t/=10;
		}
		if(ans>y)
		{
			cout<<i-1;
			return 0;
		}
		if(ans==y)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

赛后题解:

先二分一下 nn ,然后check里面写数位dp,统计 xx 的个数,最后输出 ltlt 即可。

补题代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=2000020;
int dp[110][110];
int num[N];
int dfs(int pos,int sum,int limit,int all0,int shu)
{
	if(pos==0)
	{
		return sum;
	}
	if(limit==0&&all0==0&&dp[pos][sum]!=-1)return dp[pos][sum];
	int tmp=limit?num[pos]:9;
	int ans=0;
	for(int i=0;i<=tmp;i++)
	{
		if(shu==0&&i==0&&all0==1)
		{
			ans+=dfs(pos-1,sum,limit&&i==tmp,all0&&i==0,shu);
		}
		else ans+=dfs(pos-1,sum+(i==shu),limit&&(i==tmp),all0&&(i==0),shu);
	}
	if(all0==0&&limit==0)dp[pos][sum]=ans;
	return ans;
}
int cal(int x,int shu)
{
	int cnt=0;
	while(x!=0)
	{
		cnt++;
		num[cnt]=x%10;
		x/=10;
	}
	memset(dp,-1,sizeof dp);
	return dfs(cnt,0,1,1,shu);
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x,y;
	cin>>x>>y;
	int lt=0-1,rt=1e18+1;
	while(lt+1<rt)
	{
		int mid=(lt+rt)/2;
		if(cal(mid,x)>y)rt=mid;
		else lt=mid;
	}
	
	cout<<lt;
	return 0;
}

时间复杂度:O(18*log n)

原文