Codeforces Round #667 (Div. 3) ABCD

https://codeforces.com/contest/1409

A. Yet Another Two Integers Problem

题目大意:

k∈[1;10] 我们每次可以选择 a:=a+k or a:=a−k

问a要经历多少次操作变成b?
input 
6
5 5
13 42
18 4
1337 420
123456789 1000000000
100500 9000
output 
0
3
2
92
87654322
9150
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=10000200,M=2002;
const LL mod=1e9+7;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL a,b;
        cin>>a>>b;
        LL sum=abs(a-b);
        LL res=sum/10;
        if(sum%10!=0) res++;
        cout<<res<<endl;
    }
    return 0;
}

B. Minimum Product

题目大意:

给定a,b,x,y和n,我们每次可以把a减掉一次,或者b减掉一次,最多总操作数是n次;

但是必须保证a>=x,b>=y;

问我们a*b的最大值是多少?
input
7
10 10 8 5 3
12 8 8 7 2
12343 43 4543 39 123212
1000000000 1000000000 1 1 1
1000000000 1000000000 1 1 1000000000
10 11 2 1 5
10 11 9 1 10
output 
70
77
177177
999999999000000000
999999999
55
10

找规律即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=10000200,M=2002;
const LL mod=1e9+7;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL a,b,x,y,n;
        cin>>a>>b>>x>>y>>n;
        LL minn=MAXN;
        LL a1=0,b1=0;
        a1=max(x,a-n);
        b1=max(y,b-(n-(a-a1)));
        minn=min(minn,a1*b1);
        //cout<<a1<<" "<<b1<<endl;

        b1=max(y,b-n);
        a1=max(x,a-(n-(b-b1)));
        minn=min(minn,a1*b1);
        //cout<<a1<<" "<<b1<<endl;

        cout<<minn<<endl;
    }
    return 0;
}

C. Yet Another Array Restoration

题目大意:

给定数组总个数,以及数组中必定包含的两个数字

让我们构建出方差一致的数组a(保证数组a一定存在)。
input 
5
2 1 49
5 20 50
6 20 50
5 3 8
9 13 22
output 
1 49 
20 40 30 50 10
26 32 20 38 44 50 
8 23 18 13 3 
1 10 13 4 19 22 25 16 7 
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=10000200,M=2002;
const LL mod=1e9+7;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n,x,y;
        cin>>n>>x>>y;
        if(n==2)
        {
            cout<<x<<" "<<y<<endl;
        }
        else
        {
            LL rest=y-x;
            LL num=n-1;
            while(rest%num!=0)
            {
                num--;
            }
            LL ad=rest/num;
            //cout<<num<<" "<<ad<<endl;
            LL sum=num+1;
            vector<LL> v;
            //cout<<"sum "<<sum<<endl;
            if(n>sum)
            {
                LL idx=1;
                while(x-idx*ad>=1&&n>sum)
                {
                    v.push_back(x-idx*ad);
                    sum++;
                    idx++;
                }
                idx=1;
                while(sum<n)
                {
                    v.push_back(y+idx*ad);
                    sum++;
                    idx++;
                }
            }
            for(LL i=x;i<=y;i+=ad)
            {
                v.push_back(i);
            }
            for(LL i=0;i<v.size();i++)
            {
                cout<<v[i]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}

D. Decrease the Sum of Digits

题目大意:

问我们这个数字n能够满足数位<=m的最小变化次数是多少?

每次变化就是+1。
input 
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
output 
8
0
500
2128012501878
899999999999999999

abc有一个和这个好像的!!!

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
const LL mod=1e9+7;
LL idx[N],sum[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        for(int i=0;i<=18;i++)
        {
            if(i==0) idx[i]=1;
            else idx[i]=idx[i-1]*10;
        }
        string s=to_string(n);
        s=" "+s;
        for(int i=1;i<s.size();i++)
        {
            sum[i]=sum[i-1]+(s[i]-'0');
        }
        LL odd=n;
        LL now=n;
        for(int i=s.size()-1,k=1;i>=1;i--,k++)
        {
            if(sum[i]>m)
            {
                now/=idx[k];
                now*=idx[k];
                now+=idx[k];
            }
            //cout<<now<<endl;
            s=to_string(now);
            s=" "+s;
            for(int j=1;j<s.size();j++)
                sum[j]=sum[j-1]+(s[j]-'0');
        }
        //cout<<now<<endl;
        cout<<now-odd<<endl;
    }
    return 0;
}
posted @ 2022-11-01 21:43  Vijurria  阅读(18)  评论(0编辑  收藏  举报