Codeforces Round #667 (Div. 3) abcd

本来准备鸽了的 但后来还是打了
打开电脑 登进比赛 zw他们都过了一题了
然后 b题x,y写反了wa4发
c题题目意思一开始没搞懂 又浪费了好久时间
d题wa2代码第二天早上重新看了下 加了个等号就a了
整个打下来有点想死 心态崩了
估计又要掉分

A. Yet Another Two Integers Problem

题目思路

一个很简单的贪心问题
直接做差除10再向上取整就好了

ac代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include  <map>
#include <set>
#include <utility>
#define pi 3.1415926535898
#define ll long long
#define lson rt<<1
#define rson rt<<1|1
#define eps 1e-6
#define ms(a,b) memset(a,b,sizeof(a))
#define legal(a,b) a&b
#define print1 printf("111\n")
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000007;
//998244353

int a[maxn];

int main()
{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        int tem=abs(n-m);
        if(tem%10==0)
            printf("%d\n",tem/10);
        else
            printf("%d\n",tem/10+1);
    }
}

B. Minimum Product

题目思路

这题也很简单
就对情况分个类
然后对各个类按照题目要求处理就好了

ac代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include  <map>
#include <set>
#include <utility>
#define pi 3.1415926535898
#define ll long long
#define lson rt<<1
#define rson rt<<1|1
#define eps 1e-6
#define ms(a,b) memset(a,b,sizeof(a))
#define legal(a,b) a&b
#define print1 printf("111\n")
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000007;
//998244353

ll a,b,x,y,n;

ll cal(ll a,ll b,ll x,ll y,ll n)
{
    ll ans=1e18;
    ll temn=n;
    if(b-y>=n)
    {
        ans=min(ans,1ll*a*(b-n));
    }else
    {
        n-=b-y;
        int m=min(a-x,n);
        a-=m;
        ans=min(ans,1ll*a*(y));
    }
    return ans;
}

int main()
{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        scanf("%lld%lld%lld%lld%lld",&a,&b,&x,&y,&n);
        ll ans=1e18;
        ans=min(ans,cal(a,b,x,y,n));
        ans=min(ans,cal(b,a,y,x,n));
        printf("%lld\n",ans);
    }
}

C. Yet Another Array Restoration

题目思路

题目要求输出包含下x和y的n个排序后等差的数组
并且要求这个数组的最大值最小
观察到题目的n很小
直接对y和x做差 找x到y的公差就好了
这个公差不一定是最小的
因为如果公差太小 x到y之间的值就超过了n个 最终y不被输出
如果x到y之间满足条件的值少于n
就先从小于x的值补 在不够就从大于y的值补

ac代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include  <map>
#include <set>
#include <utility>
#define pi 3.1415926535898
#define ll long long
#define lson rt<<1
#define rson rt<<1|1
#define eps 1e-6
#define ms(a,b) memset(a,b,sizeof(a))
#define legal(a,b) a&b
#define print1 printf("111\n")
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000007;
//998244353

int n,x,y;

int main()
{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        scanf("%d%d%d",&n,&x,&y);
        if(n==2)
        {
            printf("%d %d\n",x,y);
        }else
        {
            int tem=y-x;
            int num=0;
            for(int i=n-1;i>=1;i--)
            {
                if(tem%i==0)
                {
                    num=i;
                    break;
                }
            }
            tem=tem/num;
            if(num!=n)num++;
            //printf("%d\n",num);
            for(int i=0;i<num;i++)
            {
                printf("%d ",x+i*(tem));
            }
            //printf("\n");
            while(num<n)
            {
                if(x-tem>=1)
                {
                    x-=tem;
                    printf("%d ",x);
                    num++;
                }else
                {
                    y+=tem;
                    printf("%d ",y);
                    num++;
                }
            }
            printf("\n");
        }
    }
}

D. Decrease the Sum of Digits

题目思路

对于这题 我们可以先找到要满足s n需要改变到的值
再将它和n相减就好了
我们可以先统计n的每个数位上值的和
从小的数位往大的数位 判断需要改变到的最小数位
然后从大往小乘回来就好了
具体操作看代码

ac代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include  <map>
#include <set>
#include <utility>
#define pi 3.1415926535898
#define ll long long
#define lson rt<<1
#define rson rt<<1|1
#define eps 1e-6
#define ms(a,b) memset(a,b,sizeof(a))
#define legal(a,b) a&b
#define print1 printf("111\n")
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000007;
//998244353

int mp[30],ans[30];
int main()
{
    int _;
    scanf("%d",&_);
    int cnt=0;
    while(_--)
    {
        cnt++;
        //if(cnt==50)printf("nn\n");
        ll n,s;
        scanf("%lld%lld",&n,&s);
        ans[0]=0;
        for(int i=1;i<=30;i++)
            mp[i]=ans[i]=0;
        ll tem=n;
        ll sum=0;
        ll num=0;
        while(tem>0)
        {
            num++;
            sum+=tem%10;
            mp[num]=tem%10;
            ans[num]+=ans[num-1]+mp[num];
            tem/=10;
        }
        //printf("%d\n",num);
        if(sum<=s)
        {
            printf("0\n");
        }else
        {
            int flag=0;
            //printf("%d\n",ans[1]);
            for(int i=2;i<=num;i++)
            {
                if(sum-ans[i-1]+1<=s)
                {
                    flag=i;
                    break;
                }
            }

            if(flag!=0)
            {
                ll ans1=0;
                for(int i=num;i>=flag;i--)
                {
                    if(i!=flag)
                    {
                        ans1=ans1*10+mp[i];
                    }else
                    {
                        ans1=ans1*10+mp[i]+1;
                    }
                }
                for(int i=flag-1;i>=1;i--)
                {
                    ans1*=10;
                }
                printf("%lld\n",ans1-n);
            }else
            {
                ll ans1=1;
                for(int i=1;i<=num;i++)
                {
                    ans1*=10;
                }
                printf("%lld\n",ans1-n);
            }
        }
    }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值