资讯详情

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

刷题证明

A CodeForces 1611B Team 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;      }
B CodeForces 202A LLPS
#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;  }
C CodeForces 1138A Sushi 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;    }
D CodeForces 1605A A.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; }
E CodeForces 1606A AB 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; } 
F CodeForces 1594A Cnsecutive 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;
    }
}
G CodeForces 1604A Era
#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;
}
H CodeForces 1583A Windblume 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;

}
I CodeForces 166A Rank 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;

}

标签: 202a交流电流变送器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台