Codeforces 919B (Prefect Number)

编程入门 行业动态 更新时间:2024-10-26 11:27:35

<a href=https://www.elefans.com/category/jswz/34/1770097.html style=Codeforces 919B (Prefect Number)"/>

Codeforces 919B (Prefect Number)

We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.

Input
A single line with a positive integer k (1 ≤ k ≤ 10 000).

Output
A single number, denoting the k-th smallest perfect integer.

Examples
inputCopy
1
output
19
inputCopy
2
output
28
Note
The first perfect integer is 19 and the second one is 28.

题意:

先给出了完美数的定义:一个数的所有数位和为10.如181=1+8+1=10 是完美数。然后输入一个n,问你第n个完美数是什么。

思路:

我也不知道第一遍的时候脑子怎么了,竟然认为从19向上每次加9就成立,确实至少是很多成立的但却是错误的。
然后看了一下数据量和给出的时间,这个题目完全可以暴力判断打表。做这个题的时候自己一定是脑子瓦特了 哈

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>using namespace std;
const int N=1e5+10;
long long a[N],b[N];int f(int x)//判断是否是完美数的函数
{int sum=0;while(x){sum+=x%10;x/=10;if(sum>10)//这里剪枝一下 这样会省一部分时间return 0;}if(sum==10)return 1;elsereturn 0;
}int main()
{ios::sync_with_stdio(false);int k=1;for(long long i=19; k<=10010; i++)//打表 这里k是小于10000所以就{if(f(i)==1){a[k++]=i;}}long long n;while(cin>>n){cout<<a[n]<<endl;}return 0;
}

更多推荐

Codeforces 919B (Prefect Number)

本文发布于:2024-02-11 23:43:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1684357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Codeforces   Number   Prefect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!