2019 JUST Programming Contest

2019 JUST Programming Contest(2020.4.19)

C、Large GCD

打个表看下规律。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t; cin >> t;
    while (t--)
    {
        int n, m; cin >> n >> m;
        if ((n + m) % 2) cout << 2 << endl;
        else cout << 12 << endl;
    }
    return 0;
}

G、The Special King

瞎搞。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int abs(int a)
{
    return a < 0? -a: a;
}
int main()
{
    int t; cin >> t;
    while (t--)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        printf("%d\n", abs(x1 - x2) + abs(y1 - y2));
    }
    return 0;
}

H、The Universal String

还是瞎搞。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t; cin >> t;
    while (t--)
    {
        string s; cin >> s;
        bool flag = 0;
        for (int i = 1; i < s.length(); ++i)
            if ((s[i - 1] - 'a' + 1) % 26 != (s[i] - 'a'))
            {
                flag = 1; break;
            }
        if (flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

J、Grid Beauty

这题居然看完题目就想到了…我都觉得不可思议

题意就是一行的数可以任意交换,使某一列的相邻元素相同。输出最大能获得的相同相邻元素对数。

发现某一行的状态只与上一行有关,于是我们只需要把当前行和上一行相同的元素摆在一起就可以了。

利用map统计一下。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t; cin >> t;
    while (t--)
    {
        static int a[1010][1010];
        int n, m; scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= m; ++j)
                scanf("%d", &a[i][j]);
        ll ans = 0;
        for (int i = 1; i < n; ++i)
        {
            map <int, int> mp;
            for (int j = 1; j <= m; ++j)
                mp[a[i][j]]++;
            for (int j = 1; j <= m; ++j)
                if (mp[a[i + 1][j]]) ++ans, --mp[a[i + 1][j]];
        }
        cout << ans << endl;
    }
    return 0;
}

K、Subarrays OR

这题我就觉得很不科学。暴力AC了。

感觉这题唯一学到的东西就是利用set去重。

说实话我感觉这题用set也会超时,毕竟每次循环都要对容器里的元素遍历一遍…

如果n实打实达到了1e5肯定是超的。不过网上题解好像也都是set做的。不管了。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int t; cin >> t;
    while (t--)
    {
        int n; cin >> n;
        static int a[100010];
        for (int i = 1; i <= n; ++i)
            scanf("%d", &a[i]);
        set <int> ans, sav, now;
        for (int i = 1; i <= n; ++i)
        {
            now.clear(); now.insert(a[i]);
            for (auto &j: sav) now.insert(j | a[i]);
            sav = now;
            for (auto &j: sav) ans.insert(j);
        }
        printf("%d\n", ans.size());
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36000896/article/details/105617577