Educational Codeforces Round 122 (Rated for Div. 2) ABC

Problem - A - Codeforces

题目大意:把一个整数n,通过改变它的最低位数字来使得它是7的倍数。

注意的是需要不能含有前导0。

 input

3
42
23
377

output

42
28
777

 直接控制它的最低位不能越界就成。

#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t,n,m;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n%7==0) cout<<n<<endl;
        else
        {
            if(n%10>=n%7) cout<<n-n%7<<endl;
            else cout<<n+(7-n%7)<<endl;
        }
    }
    return 0;
}

Problem - B - Codeforces

题目大意:给定一个只有0和1组成的字符串s,选取一个子字符串,如果0的个数>1,那么删除1的个数,反之如果1的个数>0,那么删除0的个数。

重点(wa点)来了:If the amounts are the same, do nothing.

input

4
01
1010101010111
00110001000
1

output

0
5
3
0

 If the amounts are the same, do nothing. 如果sum0==sum1,啥都别干?

WA了一次+再读一遍题目发现:选取子串,还得删除最大的数量,那么如果我有一串s:“010101”

如果我选取整串,就只能得到0

然而如果我从其中选取字串“01010”,就成功地发现了大小之分,so↓

#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t,n,m;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int one=0,zero=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='0') zero++;
            else one++;
        }
        if(zero==one) cout<<zero-1<<endl;
        else cout<<min(zero,one)<<endl;
    }
    return 0;
}

Problem - C - Codeforces

题目大意:游戏角色生命值hc,攻击力dc;怪兽生命值hm,攻击力dm。

大战前角色有k个硬币,一个硬币分别可购买w的攻击力,或者是a的生命值。

问角色能不能打赢怪兽?

input

4
25 4
9 20
1 1 10
25 4
12 20
1 1 10
100 1
45 2
0 4 10
9 2
69 2
4 2 7

output

YES
NO
YES
YES

注意:判断条件如果写成 ca/d>=c/cb会wa。而要写成(角色的生命值+怪兽的攻击力-1)/怪兽的攻击力>=(怪兽的生命值+角色的攻击力-1)/角色的攻击力。因为会遇到余数的问题,所以需要向上取整ceil

eg:(5+2-1)/2=3     5/2=2;

#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        LL a,b,c,d,k,bb,aa;
        cin>>a>>b>>c>>d>>k>>bb>>aa;
        bool flag=false;
        for(LL i=0;i<=k;i++)
        {
            LL ca=a+i*aa;
            LL cb=b+(k-i)*bb;
            //cout<<ca<<" "<<cb<<" "<<c<<" "<<d;
            if((ca+d-1)/d>=(cb+c-1)/cb)
            {
                flag=true;
                cout<<"YES"<<endl;
                break;
            }
        }
        if(flag==false) cout<<"NO"<<endl;
    }
    return 0;
}
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值