NCD 2019

C. Hasan and his lazy students

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + 10;
ll sum[N][N];
int dp[N], a[N];
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        int n;
        scanf("%d", &n);
        memset(sum, 0, sizeof(sum));
        int maxx = 1;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", a + i);
            dp[i] = sum[i][1] = 1;
            for (int j = 0; j < i; j++)
            {
                if (a[j] < a[i])
                {
                    dp[i] = max(dp[i], dp[j] + 1);
                    sum[i][dp[j] + 1] = (sum[i][dp[j] + 1] + sum[j][dp[j]]) % mod;
                    maxx = max(maxx, dp[i]);
                }
            }
        }
        ll res = 0;
        for (int i = 0; i < n; i++) res = (res + sum[i][maxx]) % mod;
        printf("%d %lld\n", maxx, res);
    }
    return 0;
}

D. Football Cup

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        if (x == y) puts("Iskandar");
        else if (x > y) puts("Bashar");
        else puts("Hamada");
    }
    return 0;
}

F. Research projects

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int cass;
    for (cin >> cass; cass; cass--)
    {
        ll n, k;
        scanf("%lld%lld", &n, &k);
        if (n == k)
        {
            puts("0");
            continue;
        }
        ll ans = (n - k) / 6;
        if ((n - k) % 6) ans++;
        printf("%lld\n", ans);
    }
    return 0;
}

H. Mr. Hamra and his quantum particles

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, q;
int p[N];
int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        string ans;
        scanf("%d%d%d", &n, &m, &q);
        for (int i = 1; i <= n; i++) p[i] = i;
        int x, y;
        while (m--)
        {
            scanf("%d%d", &x, &y);
            if (find(x) != find(y)) p[find(x)] = find(y);
        }
        while (q--)
        {
            scanf("%d%d", &x, &y);
            if (find(x) == find(y)) ans += '1';
            else ans += '0';
        }
        cout << ans << "\n";
    }
    return 0;
}

L. Chemistry Exam

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        int n, ans;
        scanf("%d", &n);
        for (int i = 0, x; i < n; i++)
        {
            scanf("%d", &x);
            for (ans = 0; x; x /= 2) ans += x & 1;
            if (i) printf(" ");
            printf("%d", ans);
        }
        puts("");
    }
    return 0;
}

M. NCD Salary

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        int B1, P1, B2, P2;
        scanf("%d%d%d%d", &B1, &P1, &B2, &P2);
        if (!B1 || !B2)
        {
            if (B1 == B2) puts("Lazy");
            else if (B1 > B2) puts("HaHa");
            else puts("Congrats");
            continue;
        }
        double x = P1 * log(B1), y = P2 * log(B2);
        if (fabs(x - y) <= 1e-7) puts("Lazy");
        else if (x > y) puts("HaHa");
        else puts("Congrats");
    }
    return 0;
}

 

上一篇:fastadmin自定义导入回调


下一篇:linux-高可用/七层负载均衡/四层负载均衡