C - Even Digits Editorial
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 300300 points
Problem Statement
A non-negative integer �n is called a good integer when it satisfies the following condition:
- All digits in the decimal notation of �n are even numbers (00, 22, 44, 66, and 88).
For example, 00, 6868, and 20242024 are good integers.
You are given an integer �N. Find the �N-th smallest good integer.
Constraints
- 1≤N≤10^12
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the N-th smallest good integer.
Sample Input 1Copy
Copy
8
Sample Output 1Copy
Copy
24
The good integers in ascending order are 0,2,4,6,8,20,22,24,26,28,…0,2,4,6,8,20,22,24,26,28,….
The eighth smallest is 2424, which should be printed.
Sample Input 2Copy
Copy
133
Sample Output 2Copy
Copy
2024
Sample Input 3Copy
Copy
31415926535
Sample Output 3Copy
Copy
200662886824422
题解:
要精用vector,防止超时。文章来源:https://www.toymoban.com/news/detail-806591.html
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a;//类似高精度
int n;
signed main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> n;
n-=1;//因为第一位是0嘛
while(n > 0){//2*5=10进位了
a.push_back(n%5);
n /= 5;
}
if(a.empty()) a.push_back(0);
for(int i = a.size()-1; i > -1; i--)//迭代器,也不算吧,vector也是数组
cout << 2*a[i];
}文章来源地址https://www.toymoban.com/news/detail-806591.html
到了这里,关于AtCoder Beginner Contest 336 C - Even Digits题解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!