NCD 2019

A. Hasan the lazy judge

B. Let me sleep

C. Hasan and his lazy students

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
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;
}
View Code

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;
}
View Code

E. Adnan and the Burned drivers

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;
}
View Code

G. Ali and the Breakfast

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;
}
View Code

J. Bashar and daylight saving time

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
int x[N], a[N];
void add(int L, int R)
{
    x[L]++, x[R + 1]--;
}
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        memset(x, 0, sizeof x);
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= m; i++) scanf("%d", a + i);
        for (int i = 1, y; i <= m; i++)
        {
            scanf("%d", &y);
            if (!y) add(a[i], a[i]);
            else if (abs(y) == n) add(1, n), add(a[i], a[i]);
            else if (abs(y) == n - 1) add(1, n);
            else
            {
                int e = (a[i] + (y % n + n) % n - 1) % n + 1;
                if (y > 0)
                {
                    if (e >= a[i]) add(a[i], e);
                    else add(a[i], n), add(1, e);
                }
                else
                {
                    if (e <= a[i]) add(e, a[i]);
                    else add(1, a[i]), add(e, n);
                }
            }
        }
        for (int i = 1; i <= n + 1; i++) x[i] += x[i - 1];
        int ans1 = 0, ans2 = 0;
        for (int i = 1; i <= n; i++)
            if (x[i] > ans1) ans1 = x[i], ans2 = i;
        printf("%d %d\n", ans2, ans1);
    }
    return 0;
}
View Code

K. Masaoud LOVES PIZZAS

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
ll a[N], sum[N];
int main()
{
    int cass;
    for (scanf("%d", &cass); cass; cass--)
    {
        int n, x;
        scanf("%d%d", &n, &x);
        for (int i = 1; i <= n; i++)
        {
            scanf("%lld", a + i);
            sum[i] = sum[i - 1] + a[i];
        }
        ll ans = 0;
        for (int i = 1; i <= n; i++)
        {
            int l = i, r = n, res = 0;
            while (l <= r)
            {
                int mid = (l + r) / 2;
                if (sum[mid] - sum[i - 1] < x) l = mid + 1, res = mid;
                else r = mid - 1;
            }
            ans += max(0, res - i + 1);
        }
        printf("%lld\n", ans);
    }
    return 0;
}
View Code

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;
}
View Code

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;
}
View Code

 

posted @ 2022-01-04 15:28  ゼロツー  阅读(98)  评论(0)    收藏  举报
Live2D Title