0
点赞
收藏
分享

微信扫一扫

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

独孤凌雪 2022-02-12 阅读 66
c++

Problem - A - Codeforces

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

#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

 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

注意:判断条件如果写成 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;
}
举报

相关推荐

0 条评论