首页 > 其他 > 详细

【ATcoder】AtCoder Beginner Contest 165

时间:2020-05-05 16:23:28      阅读:64      评论:0      收藏:0      [点我收藏+]

这次ABC好水啊

A - We Love Golf

暴力枚举[A, B]之间的数即可

#include <iostream>
#include <cstdio>
using namespace std;
int a, b, k;
int main() {
    cin >> k;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}

B - 1%

观察到最大也只有3760天,直接暴力搞,然后判断即可。

#include <iostream>
#include <cstdio>
using namespace std;
long long cur = 100;
long long n;
int main() {
    cin >> n;
    for (int i = 1; i <= 10000; i++) {
        cur = cur + cur * 0.01;
        if (cur >= n) {
            cout << i;
            return 0;
        }
    }
    return 0;
}

C - Many Requirements

看到数据范围,发现直接暴搜所有情况在取最大值即可,复杂度$O(C_m^n \times Q)$

#include <iostream>
#include <cstdio>
using namespace std;
int n, m, q;
int a[100], b[100], c[100], d[100];
int s[20], ans;
void dfs(int cur, int lst) {
    if (cur > n) {
        int cnt = 0;
        for (int i = 1; i <= q; i++) {
            if (s[b[i]] - s[a[i]] == c[i]) {
                cnt += d[i];
            }
        }
        ans = max(ans, cnt);
        return;
    }
    for (int i = lst; i <= m; i++) {
        s[cur] = i;
        dfs(cur + 1, i);
    }
}
int main() {
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(1, 1);
    cout << ans;
    return 0;
}

 

D - Floor Function

设函数 $f(x)=floor(Ax/B)+A \times floor(x/B)$,不难发现 $f(x)=f(x+B)$(其实考试的时候打一打表就发现了)。

故我们只需考虑 $x \in [0,B-1]$。

所以 $f(x)=floor(Ax/B)$,而 $floor(Ax/B)$ 是单调上升的,所以在 $x=B-1$ 时 $f(x)$ 取得最大值。

如果 $N < B-1$ 则在 $N$ 取得最大值。

#include <iostream>
#include <cstdio>
using namespace std;
long long a, b, n;
int main() {
    cin >> a >> b >> n;
    long long i = min(b - 1, n);
    cout << (a * i) / b - a * (i / b) << " ";
    return 0;
}

E - Rotation Matching

只需在每个竞技场的差不同且最靠边即可。

所以我们可以构造(1,m+1) (2,m)...差为m,m-2,m-4...

(m+2,2*m+1)(m+3,2*m)...差为m-1,m-3...

共m组

#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int main() {
    cin >> n >> m;
    for (int i = 1, j = m + 1; i < j; i++, j--) {
        cout << i << " " << j << endl;
    }
    for (int i = m + 2, j = 2 * m + 1; i < j; i++, j--) {
        cout << i << " " << j << endl;
    }
    return 0;
}

 

F - LIS on Tree

一裸题,不讲了。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
    int pre, to;
}edge[400010];
int head[200010], tot;
int n, a[200010];
int low[200010], cnt;
int ans[200010];
void add(int u, int v) {
    edge[++tot] = node{head[u], v};
    head[u] = tot;
}
void dfs(int x, int fa) {
    ans[x] = cnt;
    for (int i = head[x]; i; i = edge[i].pre) {
        int y = edge[i].to;
        if (y != fa) {
            if (low[cnt] < a[y]) {
                int b = cnt;
                low[++cnt] = a[y];
                dfs(y, x);
                cnt = b;
            } else {
                int p = lower_bound(low + 1, low + cnt + 1, a[y]) - low;
                int v = low[p];
                low[p] = a[y];
                dfs(y, x);
                low[p] = v;
            }
        }
    }
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        add(u, v);
        add(v, u);
    }
    low[++cnt] = a[1];
    ans[1] = cnt;
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

 

【ATcoder】AtCoder Beginner Contest 165

原文:https://www.cnblogs.com/zcr-blog/p/12830364.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!