CF1835A k-th equality

// LUOGU_RID: 129858861
/*
A+b[b-1]>c[c]-1
A+b[b]-1<c[c-1]

c[c-1]~~~~~~~~~~~              c[c]-1
    A+b[b-1]    A+b[b]-1    
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
//#include<queue>
//#include<vector>
//#include<bits/stdc++.h>
#define ll long long
#define ddd printf("-----------------------\n");
using namespace std;
const int maxn=1e1 +10;
const int mod=998244353;
const int inf=0x3f3f3f3f;

ll p[20]={1};
ll a,b,c,k;

void solve(ll a,ll b,ll c,ll k)
{
    ll cnt=0;
    for(int A=p[a-1];A<=p[a]-1;A++)
    {
        if(A+p[b-1]>p[c]-1||A+p[b]-1<p[c-1]) continue;
        int l=max(p[c-1],A+p[b-1]),r=min(p[c]-1,A+p[b]-1);
        //if(l>r) continue;
        if(cnt+(r-l+1)>=k)
        {
            cout<<A<<" + "<<l+(k-cnt-1)-A<<" = "<<l+(k-cnt-1)<<'\n';
            return;
        }
        else cnt+=(r-l+1);
    }
    cout<<"-1\n";
}/*
void solve(){
    ll cnt=0;
    for(int A=p[a-1];A<p[a];++A){
        int l=max(p[b-1]+A,p[c-1]),r=min(p[b]-1+A,p[c]-1);
        if(l>r)
            continue;
        if(cnt+(r-l+1)>=k){
            cout<<A<<" + "<<l+(k-cnt-1)-A<<" = "<<l+(k-cnt-1)<<endl;
            return;
        }
        cnt+=(r-l+1);//exceed
    }
    cout<<"-1\n"<<endl;
}*/

int main()
{
    ios::sync_with_stdio(false);
    for(int i=1;i<=10;i++) p[i]=p[i-1]*10;
    int T;cin>>T;
    while(T--)
    {
        cin>>a>>b>>c>>k;
        solve(a,b,c,k);
    }

    return 0;
}

 

posted @ 2023-10-22 09:04  JMXZ  阅读(7)  评论(0)    收藏  举报