《看了受制了》第十二天,4道题,合计53道题

发布时间 2023-09-06 21:50:34作者: wxzcch

2023年9月6日

今天是Atcoder、ACWING、牛客。
预告!!已经再出Atcoder的爬虫翻译了(慢慢集成一下,数学建模完成后完善)。

ACWING5199 现代艺术

题目理解

  • 这个题目以a数组作为横行的操作次数,b数组为纵向的操作次数。
  • 然后每一个位置的操作次数便是a[i] + b[j]就是第(i, j)的操作次数。
  • 偶数为黑色、奇数为金色

代码实现

#include<iostream>
#include<cstring>
using namespace std;

const int N = 5e6;

int a[N], b[N];
int n, m, k;
int main()
{
    cin >> n >> m >> k;

    while(k -- )
    {
        char c;
        int p;
        cin >> c >> p;
        if(c == 'R')
            a[p]++;
        else
            b[p]++;
    }

    int res = 0;
    for(int i = 1; i <= n ; i++)
        for(int j = 1; j <= m; j++)
            if((a[i] + b[j]) % 2)
                res++;

    cout << res;
    return 0;
}

牛客每日一刷 游游的字符重排

题目理解

就是全排列。
但是这个不是知道为啥手敲过不了,用内置的过了。学到新东西next_permutation遍历全排列。

代码实现

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

string s;

bool check(string p)
{
    for(int i = 0; i < p.size() - 1; i++)
        if(p[i] == p[i + 1])
            return false;
    
    return true;
}


int main()
{
    int res = 0;
    cin >> s;
    sort(s.begin(),s.end());
    do{
        if(check(s))
            res++;
    }while(next_permutation(s.begin(), s.end()));
    
    cout << res;
    return 0;
}

牛客每日一题 柜台结账

题目理解

用整数来换算,不要用小数,会有精度问题。

代码实现

a1, a2 = map(int, input().split())
l = len(str(a2))

if a2 == 0:
    print("PLMM")
elif a2 < 5*pow(10, l-1) or a2 == 5*pow(10, l-1) and a1 % 2 == 0:
    print("Happy birthday to YXGG")
else:
    print("Happy birthday to MFGG")

AtcoderABC080 B Harshad Number

题目理解

就是数位求和,然后取模

代码实现

#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int t = n;
    int sum = 0;
    
    while(n)
    {
        sum += n % 10;
        n /= 10;
    }
    
    if(t % sum)
        cout << "No";
    else
        cout << "Yes";
    
    return 0;
}