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

本文记录了作者在2021年12月23日参与蓝桥杯竞赛时的刷题经历,详细阐述了做题过程与心得。
摘要由CSDN通过智能技术生成

刷題證明

ACodeForces 1611BTeam Composition: Programmers and Mathematicians

 

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t, n, m;
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        if (n > m)
        {
            int temp = m;
            m = n;
            n = temp;
        }
        int ans = min(n, min(m, (n + m) / 4));
        cout << ans << endl;

    }
BCodeForces 202ALLPS
#include<bits/stdc++.h>
#include<map>
using namespace std;
int main()
{
    string s;
    map<char, int>mp;
    cin >> s;
    for (int i = 0; i <s.size(); i++)
    {
        mp[s[i]]++;
    }
    for (int i = 'z'; i >= 'a'; i--)
    {
        if (mp[i] != 0)
        {
            for (int j = 0; j <mp[i];j++)
            {
                cout << (char)i;
            }
            return 0;
        }

    }
    return 0;

}
CCodeForces 1138ASushi for Two

 

#include<bits/stdc++.h>
using namespace std;
int arr[100005];
int main()
{
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int sit = arr[0], cnt1 = 0, cnt2 = 0;
    if (arr[0] == 1)cnt1 = 1;
    else cnt2 = 1;
    for (int i = 1; i < n; i++)
    {
        if (sit != arr[i])
        {
            ans = max(ans, min(cnt1, cnt2));//紀錄前面兩次的最小值
            if (sit == 1)cnt2 = 1;
            else cnt1 = 1;
            sit = arr[i];
        }
        else
        {
            if (sit == 1)cnt1++;
            else cnt2++;
        }
    }
    ans = max(ans, min(cnt1, cnt2));
    printf("%d", ans * 2);
    return 0;



}
DCodeForces 1605AA.M. Deviation

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b, c;
    int t;
    cin >> t;
    while (t--)
    {
        cin >> a >> b >> c;
        if (abs((a + c - 2 * b) % 3) == 0)
        {
            printf("0\n");
        }
        else printf("1\n");
    }
    return 0;
}
ECodeForces 1606AAB Balance
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    char s[105] = { '0'};
    while (t--)
    {
        cin >> s;
        int ab[105] = { 0 }, ba[105] = { 0 };
        int sit = s[0];
        int abcnt = 0, bacnt = 0;
        for (int i = 1; i <strlen(s); i++)
        {
            if (s[i] != sit && s[i] == 'b')
            {
                abcnt++;
                ab[abcnt] = i;
           
              
               
                sit = 'b';
                continue;
            }
            if (s[i] != sit && s[i] == 'a')
            {
                bacnt++;
                ba[bacnt] = i;
                sit = 'a';
            
                
                continue;
            }
        }
        if (abcnt==bacnt)
        {
           
            printf("%s\n", s);
        }
        else if (abcnt>bacnt)
        {
            if (abcnt = 1 && strlen(s) != 1)
            {
                s[0] = 'b';
                printf("%s\n", s);
                continue;
            }
            for (int i = 1;i<=abcnt-bacnt;i++)
            {
                s[ab[i]-1] ='b';
               
            }
            printf("%s\n", s);
        }
        else
        {
           if (bacnt = 1 && strlen(s) != 1)
            {
                s[0] = 'a';
                printf("%s\n", s);
                continue;
            }
            for (int i =1;i<=bacnt-abcnt;i++)
            {
                s[ba[i]-1]='a';
               
            }
            printf("%s\n", s);
        }


    }
    return 0;
}
FCodeForces 1594AConsecutive Sum Riddle

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    long long n;
    while (t--)
    {
        cin >> n;
        cout << -n + 1 << " " << n << endl;
    }
}
GCodeForces 1604AEra
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, ans = 0, a;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a;
            if (a > ans + i)
            {
                ans += a - ans - i;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
HCodeForces 1583AWindblume Ode

 

#include<bits/stdc++.h>
using namespace std;
bool prime(int a)
{
    for (int i = 2; i <= sqrt(a); i++)
    {
        if ((a % i) == 0)
        {
            return 1;
        }
    }
    return 0;

}
int main()
{
    int t, n;
    cin >> t;
    while (t--)
    {
        int sum = 0, x=0, pos=0;
        int arr[205] = { 0 };
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> x;
            arr[i] = x;
            sum += arr[i];
            if ((arr[i] % 2 )!= 0)
            {
                pos = i;
            }
        }
        if (prime(sum)==1)
        {
            cout << n << endl;
            for (int i = 1; i <= n; i++)
            {
                cout << i << " ";
            }
        }
        else
        {
            cout << n - 1 << endl;
            for (int i = 1; i <= n; i++)
            {
                if (i ==(pos+1))
                {
                    continue;
                }
                cout << i << " ";
            }
        }
        cout << endl;
    }
    return 0;

}
ICodeForces 166ARank List

#include<bits/stdc++.h>
using namespace std;
long long arr[30][30];
int main()
{
    int m, x;
    cin >> m >> x;
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin >> arr[i][j];
        }
    }
    for (int i = m-1; i >0; i--)
    {
        for (int j = 0; j <= i - 1; j++)
        {
            if (arr[j][0] <arr[j + 1][0])
            {
                swap(arr[j][0], arr[j + 1][0]);
                swap(arr[j][1], arr[j + 1][1]);
            }
        }
    }
    for (int i = m - 1; i > 0; i--)
    {
        for (int j = 0; j <= i - 1; j++)
        {
            if (arr[j][1] > arr[j + 1][1]&&arr[j][0]==arr[j+1][0])
            {
                swap(arr[j][1], arr[j + 1][1]);
                swap(arr[j][0], arr[j + 1][0]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        if (arr[i][0] == arr[x-1][0] && arr[i][1] == arr[x-1][1])
        {
            ans++;
        }
   }
    cout << ans << endl;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值