2021/12/02程式培力刷題記錄

刷題證明

ACodeForces 1452ARobot Program

 

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int t,x,y;
    cin>>t;
    while(t--)
    {
       cin>>x>>y;
       if(x==y)
       {
           cout<<x+y<<endl;
       }
       else
       {
           cout<<x+y+(abs(x-y)-1)<<endl;
       }

    }
    return 0;
        


}
BCodeForces 1539BLove Song

 

#include<bits/stdc++.h>
using namespace std;
int n, q;
string s;
int sum[100005] = { 0 };
int main()
{
    int x = 0;
    cin >> n >> q;
    cin >> s;
    for (int i = 1; i <= s.size(); i++)
    {
        x = s[i - 1] - '`';
        sum[i] =sum[i-1]+ x;
    }

    while (q--)
    {
        int begin, end;
        cin >> begin >> end;
        cout << sum[end] - sum[begin-1] << endl;
    }
    return 0;

}
CCodeForces 1504ADéjà Vu
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int pos = 0;
        int ans = 0;
        cin >> s;
        int len = s.size();
        for (int i = 0; i < len; i++)
        {
            if (s[i] != 'a')
            {
                pos = len - i ;
                ans = 1;
                break;
            }
        }
        if (ans == 1)
        {
            printf("YES\n");
            for (int i = 0; i < pos; i++)
            {
                cout << s[i];
            }
            cout << 'a';
            for (int i = pos; i < len; i++)
            {
                cout << s[i];
            }
            cout << "\n";
        }
        else if (ans == 0)
        {
            printf("NO\n");
        }

    }
    return 0;

}
DCodeForces 1566AMedian Maximization
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int len,sum;
        cin>>len>>sum;
        int x=len-len/2+(len%2==0);
        cout<<sum/x<<endl;
    }
    return 0;
}
ECodeForces 1559BMocha and Red and Blue

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    char a[110];
        while (t--)
        {
            int len, check;
            cin >> len;
            check = len;
            cin >> a;
            for (int i = 0; i < len; i++)
            {
                if (a[i] != '?')
                {
                    check = i;
                    break;
                }
            }
            if (check ==len)
            {
                a[len] = 'B';
            }
            for (int i = check - 1; i >= 0; i--)
            {
                if (a[i] != '?')
                {
                    continue;
                }
                if (a[i + 1] == 'B')
                {
                    a[i] = 'R';
                }
                if (a[i + 1] == 'R')
                {
                    a[i] = 'B';
                }
            }
            for (int i = check + 1; i < len; i++)
            {
                if (a[i] != '?')
                {
                    continue;
                }
                if (a[i - 1] == 'B')
                {
                    a[i] = 'R';
                }
                if (a[i - 1] == 'R')
                {
                    a[i] = 'B';
                }
            }
            for (int i = 0; i < len; i++)
            {
                cout << a[i];
            }
            cout << endl;
            memset(a, '0', len);
        }
    return 0;
}
FCodeForces 1496ASplit it!

 

#include<bits/stdc++.h>
using namespace std;
string s;
int main(void)
{
    int t, n, k;
    cin >> t;
    while (t--)
    {
        cin >> n >> k;
        cin >> s;
        int no= 0;
        for (int i = 0, j = n - 1; i < j - 1; i++, j--)
        {
            if (s[i] != s[j])
            {
                break;
            }

            no++;
        }
        if (no>= k)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }

        fill(s.begin(), s.end(), 0);

    }
    return 0;

}
GCodeForces 1480BThe Great Hero

 

#include<bits/stdc++.h>
#define int long long
using namespace std;
int  mh[1000010];
int  ma[1000010];
signed main()
{
    int t, a, h, mn;
    cin >> t;
    while (t--)
    {
        int damage = 0;
        int residualBlood = 0;
        cin >> a >> h >> mn;
        for (int i = 0; i < mn; i++)
        {
            cin >> ma[i];
        }
        for (int i = 0; i < mn; i++)
        {
            cin >> mh[i];
        }
        for (int i = 0; i < mn; i++)
        {
            damage =damage+(mh[i] / a + (mh[i] % a != 0)) * ma[i];
        }
        for (int i = 0; i < mn; i++)
        {
            if (h - damage + ma[i] > 0)
            {
                cout << "YES" << endl;
                residualBlood++;
                break;

            }
        }
        if (residualBlood == 0)
        {
            cout << "NO" << endl;
        }


    }
    return 0;
}
HCodeForces 1562BScenes From a Memory

 

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll t, len;
char checkn[12];
char s[55];
signed main()
{
    cin >> t;
    while (t--)
    {
        int ans = 0;
        cin >> len;
        memset(s, '0', len);
        memset(checkn, '0', 11);
        cin >> s;
        for (int i = 0; i < len; i++)
        {
           checkn[s[i] - '0']++;
            if (s[i] == '1' || s[i] == '4' || s[i] == '6' || s[i] == '8' || s[i] == '9')
            {
                printf("1\n");
                cout << s[i] - '0' << endl;
                ans = 1;
                break;
            }
        }
        if (ans == 1)continue;
        for (int i = 0; i < len; i++)
        {
            if ((s[i] == '2' || s[i] == '5') && (i != 0))
            {
                cout << "2" << endl << s[i - 1] - '0' << s[i] - '0' << endl;
                ans = 1;
                break;
            }
            else if ((s[i] == '3' || s[i] == '7') && checkn[s[i] - '0']-'0' >= 2) {
                cout << "2" << endl << s[i] - '0' << s[i] - '0' << endl;
                ans = 1;
                break;
            }
        }
        if (ans == 0)
        {
            if (s[0] == '2')
                cout << "2" << endl << "27" << endl;
            else
                cout << "2" << endl << "57" << endl;
        }


    }
    return 0;
}
ICodeForces 1438BValerii Against Everyone
#include<bits/stdc++.h>
using namespace std;
int t, n, s[1001];
int x;
int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> s[i];
        }
        sort(s, s + n);
        x = 0;
        for (int i = 1; x!=1 && i < n; i++)
        {
            if (s[i] == s[i - 1])
                x = 1;
        }
        if (x == 1)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值