codeforces 1216E1(数学+暴力)

2020-10-23 15:28:56 浏览数 (1)

题意描述

思路

AC代码

代码语言:javascript复制
#include<bits/stdc  .h>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x  )
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long ll;
const int N=2*1e5 10;
const int M=1e6 10;
const int INF=0x3f3f3f3f;
const int MOD=1e9 7;
ll f[10];
void solve(){
    ll n;cin>>n;
    ll cnt=0,k=1,idx=0,t=1,cpy=n;
    while(1){
        cnt  ;
        n-=k;
        //求出如果最后n小于等于0,则加上k,获得该k属于cnt段的第几个数字
        if(n<=0){
            n =k;
            break;
        }
        //满足的话公差d加一
        if(cnt==f[idx]){
            idx  ;
            t  ;
        }
        k =t;
    }
    string s;
    //暴力构造字符串
    rep(i,1,cnt 1) s =to_string(i);
    cout<<s[n-1]<<endl;
}
int main(){
    IOS;
    f[0]=9;
    rep(i,1,10) f[i]=f[i-1]*10 9;
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}

0 人点赞