C - Even Digits?Editorial
Time Limit: 2 sec / Memory Limit: 1024 MB
Score:?300300?points
A non-negative integer?n?is called a?good integer?when it satisfies the following condition:
For example,?0,?68, and?2024?are good integers.
You are given an integer?N. Find the?N-th smallest good integer.
The input is given from Standard Input in the following format:
N
Print the?N-th smallest good integer.
Copy
8
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.
133
2024
31415926535
2006628868244228
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int fun(int n){
int p,i=0;
if(n==1)return i;
for(p=2,i=0;p<=n;p++){
i+=2;
int q=i,cnt=0;
while(q){
int t=q%10;
if(t%2!=0){i+=pow(10,cnt);break;}
q/=10;
cnt++;
}
}
return i;
}
signed main(){
cin>>n;
cout<<fun(n);
}
//这个代码能处理n<=40000000的数据
要精用vector,数组一般都会超时的啦。
#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(nullptr);
cout.tie(nullptr);
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];
}
也算是运用了算法吧这个题目,高精度还是很重要的(上一次选拔赛就是高精度差一点就提交了ac了)。
这篇不算入每日一题的范畴。是acm作业吧。