首页 > 其他分享 >P1708 [入门赛 #21] 星云 hard ver. 题解

P1708 [入门赛 #21] 星云 hard ver. 题解

时间:2024-12-12 19:09:40浏览次数:7  
标签:99999 9999 ver 题解 hard 999 999999 99 9999999

思路

看到此题,第一想到可以直接枚举,求一个数的数位之和,然后判断,可以就让方案数加一,代码如下:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    int n,k,cnt=0,ans;
    while(t--){
        cin>>n>>k;
        cnt=0;
        for(int i=1;i<pow(10,n);i++){
            ans=0;
            int temp=i;
            while(temp>0){
                ans+=(temp%10);
                temp/=10;
            }
            if(ans<=k) cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

可一测,啊,超时了?仔细一看,发现 \(T\) \(\le\) \(10^5\)。做的时候没想出来,后面看了别人的题解才发现可以打表,用一个二维数组,然后我就试了一下。温馨提示,不要用在线编译器,不然绝对超时,建议使用DEVC++

代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[7][100]={1,2,3,4,5,6,7,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,2,5,9,14,20,27,35,44,54,63,71,78,84,89,93,96,98,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,3,9,19,34,55,83,119,164,219,282,351,424,499,574,647,716,779,834,879,915,943,964,979,989,995,998,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,4,14,34,69,125,209,329,494,714,996,1344,1759,2239,2779,3371,4004,4664,5334,5994,6627,7219,7759,8239,8654,9002,9284,9504,9669,9789,9873,9929,9964,9984,9994,9998,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,9999,5,20,55,125,251,461,791,1286,2001,2997,4337,6082,8287,10997,14243,18038,22373,27213,32493,38124,43999,49999,55999,61874,67505,72785,77625,81960,85755,89001,91711,93916,95661,97001,97997,98712,99207,99537,99747,99873,99943,99978,99993,99998,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,6,27,83,209,461,923,1715,3002,5004,8001,12333,18395,26627,37499,51491,69068,90650,116577,147069,182196,221858,265775,313487,364364,417626,472373,527625,582372,635634,686511,734223,778140,817802,852929,883421,909348,930930,948507,962499,973371,981603,987665,991997,994994,996996,998283,999075,999537,999789,999915,999971,999992,999998,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,999999,7,35,119,329,791,1715,3431,6434,11439,19440,31767,50135,76679,113969,164999,233144,322079,435654,577719,751914,961439,1208819,1495679,1822544,2188679,2591984,3028959,3494754,3983319,4487634,4999999,5512364,6016679,6505244,6971039,7408014,7811319,8177454,8504319,8791179,9038559,9248084,9422279,9564344,9677919,9766854,9834999,9886029,9923319,9949863,9968231,9980558,9988559,9993564,9996567,9998283,9999207,9999669,9999879,9999963,9999991,9999998,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999,9999999};
	int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        cout<<a[n-1][k-1]<<endl;
    }
    return 0;
}

标签:99999,9999,ver,题解,hard,999,999999,99,9999999
From: https://www.cnblogs.com/zhouxi2022HZO/p/18603192

相关文章

  • 论文阅读:Statistical Comparisons of Classifiers over Multiple Data Sets
    论文地址:StatisticalComparisonsofClassifiersoverMultipleDataSets(acm.org)前面在机器学习之Friedman检验-CSDN博客中提到了Friedman检验,这里将对这个方法的论文进行详细的阅读,以了解其原理。摘要尽管用于在单个数据集上比较两种学习算法的方法已经研究了相当......
  • obsidian+picgo+chevereto+picgo图床 笔记文档图片自动上传
    简介obsidian,一款知识管理工具,它支持Markdown格式,所有你的思维、笔记和灵感都能在一个地方相互连接,形成一个井然有序的知识网络。用obsidian编辑文本,图片保存本地很大,我们上传到图床,减小文件大小方便不同工具打开使用文本,减小文本空间。文档方传送迁移。obsidian安装登陆官......
  • 题解:P11380 [GESP202412 八级] 排队
    题目传送门题意概要有nnn个人排队,其中有mmm对人必须相邻且前......
  • 通用的定时任务工具 schedule-server
    背景:我曾经在一个自动化测试平台中集成定时任务,基于APScheduler库花了好长时间解决重复执行的问题。定时任务集成在服务中也让服务变得复杂。最后,我们选择了公司其他团队go语言开发的一个定时任务服务。于是萌生了想法,和不用Python实现一个通用的定时任务服务。于是,schedule......
  • 这一周的pta上碰到的疑难问题解答(上)
    1.查找指定字符输入格式:输入的第一行是一个待查找的字符。第二行是一个以回车结束的非空字符串(不超过80个字符)。输出格式:如果找到,在一行内按照格式“index=下标”输出该字符在字符串中所对应的最大下标(下标从0开始);否则输出"NotFound"。输入样例1:mprogramming输出......
  • convert生成视频的报错处理
    一、convert生成gif报错问题:执行convert-delay12-loop1*jpg./DI4_z1.gif报错:convert-im6.q16:cacheresourcesexhausted`./DI4_z1.gif'@error/cache.c/OpenPixelCache/4095.convert-im6.q16:memoryallocationfailed`./DI4_z1.gif'@error/quantize.c/As......
  • docker部署项目,/var/lib/docker/overlay2目录满了如何清理?
    docker部署项目,/var/lib/docker/overlay2目录满了如何清理? docker部署项目,/var/lib/docker/overlay2目录满了如何清理?一、问题今天突然发现跑服务器上的项目挂了,上去看了一下原来是磁盘满了。df -h(或df-TH)【df命令是用来查看linux系统服务器文件系统的磁盘使用情况】......
  • 【YashanDB知识库】YAS-00218 string conversion failed.
    【问题分类】数据导入导出【关键字】imp、YAS-00218stringconversionfailed【问题描述】使用imp导入dump文件报错YAS-00218stringconversionfailed【问题原因分析】首先使用showparametercharacter查看数据库服务端字符集使用折半查找的方法确定数据导入具体报错的某......
  • 【YashanDB知识库】exp导出csv报错YAS-00218 string conversion failed
    【问题分类】数据导入导出【关键字】YAS-00218stringconversionfailed【问题描述】使用exp导出成csv报错YAS-00218stringconversionfailed【问题原因分析】首先使用showparametercharacter查看数据库服务端字符集,发现服务端字符集为GBK然后在文件$YASDB_HOME/client/......
  • 2023 ICPC 合肥区域赛题解 更新至 6 题(The 2023 ICPC Asia Hefei Regional Contest )
    Preface只能说阅读理解能力有待提高,\(B\)题看了半天愣是看不懂一点。只能跳了。依旧是复习篇,感觉队友当时开出来的\(dp\)难度不低,感慨张神的强大。我会在代码一些有必要的地方加上注释,签到题可能一般就不会写了.以下是代码火车头:#include<iostream>#include<algorithm>#i......