2021 ICPC Asia Taiwan Online Programming Contest

A. Olympic Ranking

#include <bits/stdc++.h>
using namespace std;
pair<int, string> p[310];
int main()
{
    int n;
    cin >> n;
    for (int i = 0, a, b, c; i < n; i++)
    {
        cin >> a >> b >> c;
        p[i].first = a * 1000000 + b * 1000 + c;
        getline(cin, p[i].second);
    }
    sort(p, p + n);
    for (int i = 1; p[n - 1].second[i]; i++)
        cout << p[n - 1].second[i];
    return 0;
}
View Code

B. Aliquot Sum

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int ans[N];
int main()
{
    for (int i = 1; i < N; i++)
        for (int j = 2 * i; j < N; j += i)
            ans[j] += i;
    int cass, x;
    for (cin >> cass; cass; cass--)
    {
        cin >> x;
        if (ans[x] > x) puts("abundant");
        else if (ans[x] < x) puts("deficient");
        else puts("perfect");
    }
    return 0;
}
View Code

C. A Sorting Problem

#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) x & -x
using namespace std;
const int N = 2e5 + 10;
ll n, res;
int a[N], tr[N];
void add(int x, int k)
{
    for (int i = x; i <= n; i += lowbit(i)) tr[i] += k;
}
int ask(int x)
{
    int sum = 0;
    for (int i = x; i >= 1; i -= lowbit(i)) sum += tr[i];
    return sum;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", a + i);
        res += ask(n) - ask(a[i]);
        add(a[i], 1);
    }
    cout << res;
    return 0;
}
View Code

D. Drunk Passenger

#include <bits/stdc++.h>
using namespace std;
pair<int, string> p[310];
int main()
{
    int n;
    cin >> n;
    for (int i = 0, a, b, c; i < n; i++)
    {
        cin >> a >> b >> c;
        p[i].first = a * 1000000 + b * 1000 + c;
        getline(cin, p[i].second);
    }
    sort(p, p + n);
    for (int i = 1; p[n - 1].second[i]; i++)
        cout << p[n - 1].second[i];
    return 0;
}
View Code

E. Eatcoin

F. Flip

G. Garden Park

H. A Hard Problem

I. ICPC Kingdom

J. JavaScript

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    int x = 0, y = 0;
    for (auto i : a)
        if (isdigit(i)) x = x * 10 + i - '0';
        else return puts("NaN"), 0;
    for (auto i : b)
        if (isdigit(i)) y = y * 10 + i - '0';
        else return puts("NaN"), 0;
    printf("%d", x - y);
    return 0;
}
View Code
 
posted @ 2022-01-13 21:31  ゼロツー  阅读(383)  评论(0编辑  收藏  举报
Live2D Title