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
#include
#include
#include
#include
#include
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%7) cout<

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
#include
#include
#include
#include
#include
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

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
#include
#include
#include
#include
#include
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<=(cb+c-1)/cb)
            {
                flag=true;
                cout<<"YES"<

你可能感兴趣的:(c++)