• AtCoder Beginner Contest 089


    A - Grouping 2

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n;
    int main(){
        cin >> n;
        cout << n / 3 << endl;
        return 0;
    }
    

    B - Hina Arare

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    set<char> s;
    int main() {
        int n;
        cin >> n;
        while (n--) {
            char x;
            cin >> x;
            s.insert(x);
        }
        if (s.size() == 3) cout << "Three" << endl;
        else
            cout << "Four" << endl;
            return 0;
    }
    

    C - March

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    LL res = 0;
    int n;
    string s;
    LL num[5];
    int main() {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> s;
            if (s[0] == 'A') num[0]++;
            if (s[0] == 'C') num[1]++;
            if (s[0] == 'H') num[2]++;
            if (s[0] == 'R') num[3]++;
            if (s[0] == 'M') num[4]++;
        }
        for (int i = 0; i <= 2; i++) {
            for (int j = i + 1; j <= 3; j++) {
                for (int k = j + 1; k <= 4; k++) {
                    res += num[i] * num[j] * num[k];
                }
            }
        }
        cout << res << endl;
        return 0;
    }
    

    D - Practical Skill Test

    给出一个NxM的矩阵,元素是1到NxM的所有数字,以及一个数字d

    现在给出q个查询(q<=1e5),每个查询有一个x和y,要求x变成x+d,花费是x和x+d在矩阵上的曼哈顿距离,直到x变为y为止

    对于每个查询,输出花费

    因为q很大,每次模拟就会爆炸,所以需要考虑离线的方法

    用一个数组res存放从最小的值变到i所花的花费,然后直接输出(res[y]-res[x])即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 3e2 + 5;
    typedef long long LL;
    int n, m, d;
    int mp[N][N];
    struct node {
        LL x, y;
    } add[N * N];
    int res[N * N];
    int main() {
        cin >> n >> m >> d;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cin >> mp[i][j];
                add[mp[i][j]].x = i;
                add[mp[i][j]].y = j;
            }
        }
        for (int i = d + 1; i <= n * m; i++) {
            res[i] = res[i - d] + abs(add[i].x - add[i - d].x) +
                     abs(add[i].y - add[i - d].y);
        }
        int q;
        cin >> q;
        while(q--){
            int x,y;
            cin >> x >> y;
            cout << res[y] - res[x] << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    【贪心 堆】luoguP2672 推销员
    【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
    「整理」[图论]最短路系列
    收集到的小玩意儿
    初遇构造函数
    在2440开发板液晶上显示两行字
    error: converting to execution character set: Invalid or incomplete multibyte or wide character
    宽字节
    宽字符wchar_t和窄字符char区别和相互转换
    linux获取文件大小的函数
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14386428.html
Copyright © 2020-2023  润新知