Codeforces Round #667 (Div. 3) 题解A-D

A:Yet Another Two Integers Problem

在这里插入图片描述
提议思路 : 两数之差除10向下取整即可
代码:

#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
using namespace std;

int main(){
    int T;
    cin >>T;
    while(T--){
        int a, b;
        cin >> a >> b;
        int c = abs(a-b);
        int ans;
        if(c % 10 == 0)
            ans = c / 10;
        else
            ans = c / 10 + 1;
        cout << ans <<endl;
    }
}

B Minimum Produc

在这里插入图片描述
题意 : 对两数进行减一操作,条件:1操作次数 2两数最小值约束
思路 : 分别对两数进行减数操作与反向加数操作,取最小值
代码

#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long

int main(){
    int T;
    cin >>T;
    while(T--){
        LL a, b, x, y, n;
        cin >> a >> b >>x >>y >>n;
        LL A = abs(a - x);
        LL B = abs(b - y);
        LL ans1 = 0;
        LL ans2 = 0;
        LL nn = (A+B) - n;
        if((A+B) <= n){
            ans1 = x*y;
            cout << ans1 <<endl;
            continue;
        }
        if(x > y){
            if(A >= nn){
                ans1 = (x+nn)*y;
            }
            else{
                ans1 = a*(y+(nn-A));
            }
        }

        else if(x < y){
            if(B >= nn){
                ans1 = (y+nn)*x;
            }
            else{
                ans1 = b*(x+(nn-B));
            }
        }

        else if(x == y){
            if(A >= B){
                if(A >= nn){
                    ans1 = (x+nn)*y;
                }
                else{
                    ans1 = a*(y+(nn-A));
                }
            }
            else{
                if(B >= nn){
                    ans1 = (y+nn)*x;
                }
                else{
                    ans1 = b*(x+(nn-B));
                }
            }
        }
        //cout <<ans <<endl;

        if(a < b){
            if(A >= n)
                ans2 = (a - n) * b;
            else{
                ans2 = x*(b-(n-A));
            }
        }

        else if(a > b){
            if(B >= n)
                ans2 = (b - n) * a;
            else{
                ans2 = y*(a-(n-B));
            }
        }

        else if(a == b){
            if(A >= B){
                if(A >= n)
                    ans2 = (a - n) * b;
                else{
                    ans2 = x*(b-(n-A));
                }
            }
            else{

                if(B >= n)
                    ans2 = (b - n) * a;
                else{
                    ans2 = y*(a-(n-B));
                }
            }
        }
        //cout << ans2 <<endl;
        LL ans = min(ans1, ans2);
        cout <<ans <<endl;
    }
}

C. Yet Another Array Restoration

在这里插入图片描述
题意 : 给出数组元素数目与两个元素,要求构造等差数列,使最大值最小
思路 : 构造等差数列,要求两个元素 : 1 公差 2 初始元素
1 公差:必为给出的两元素之差的因数,且差值与公差的商必小于元素数目
2 初始元素:从最大元素向前减,若小于零,则取模
代码:

#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
using namespace std;

int main(){
    int T;
    cin >>T;
    while(T--){
        int n, x, y;
        cin >> n >> x >> y;
        int c = abs(x-y);
        int gc = 0;
        for(int i = n-1; i >= 1; i--){
            if(c % i == 0){
                gc = c / i;
                break;
            }
        }
        int zero = y - gc*(n-1);
        if(zero <= 0)
            zero = y % gc;
        if(zero == 0)
            zero = gc;
        for(int i = 0; i < n; i++){
            cout << zero + i*gc ;
            if(i != n-1)
                cout << ' ';
            else cout <<endl;
        }
    }
}

D. Decrease the Sum of Digits

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值