0
点赞
收藏
分享

微信扫一扫

Codeforces Round #774 (Div. 2)

玩物励志老乐 2022-03-11 阅读 62
算法

太菜了,连D都写不出来,补完题目写题解

A. Square Counting

思路

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t -- ) {
        LL n, s;
        cin >> n >> s;
        cout << s / n / n << endl;
    }
    return 0;
}

B. Quality vs Quantity

思路

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a[N];
LL sum[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t -- ) {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i ++ ) cin >> a[i];
        sort(a + 1, a + n + 1);
        for (int i = 1; i <= n; i ++ ) 
            sum[i] = sum[i - 1] + a[i];
        bool ok = 0;
        for (int i = 1; i < (n + 1) / 2; i ++ ) {
            if (sum[n] - sum[n - i] > sum[i + 1]) {
                ok = 1;
                break;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C. Factorials and Powers of Two

思路

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef long long LL;
typedef vector<LL> VI;
VI res;
LL n;
void init() {
    LL ans = 2;
    for (int i = 3; i <= 150; i ++ ) {
        if (ans * i > 1e12) break;
        ans = ans * i;
        res.PB(ans);
    }
    sort(res.begin(), res.end());
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    init();
    while (t -- ) {
        cin >> n;
        int ans = INF;
        for (int i = 0; i < (1 << 12); i ++ ) {
            int j = i;
            int cnt = 0;
            int num = 0;
            LL sum = 0;
            while (j) {
                if (j & 1) {
                    sum += res[cnt];
                    num ++;
                }
                cnt ++;
                j >>= 1;
            }
            cnt = 0;
            sum = n - sum;
            if (sum < 0) continue;
            while (sum) {
                if (sum & 1) cnt ++;
                sum >>= 1;
            }
            ans = min(ans, cnt + num);
        }
        cout << ans << endl;
    }
    return 0;
}
举报

相关推荐

0 条评论