zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 156

    B

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
        int n,k,cnt = 0;
        cin >> n >> k;
        while(n) {
            n /= k;
            cnt ++;
        }
        cout << cnt ;
        return 0;
    }
    

    C

    暴力

    #include <bits/stdc++.h>
    using namespace std;
    #define endl '
    '
    const int N = 200;
    int a[N];
    int main() {
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
        int n,ans = 0x3f3f3f3f;
        cin >> n;
        for(int i = 0;i < n ; ++i) {
            cin >> a[i];
        }
        for(int i = 1;i <= 100; ++i) {
            int t = 0;
            for(int j = 0;j < n; ++j) {
                t += (a[j] - i) * (a[j] - i);
            }
            ans = min(ans,t);
        }
        cout << ans << endl;
        return 0;
    }
    

    整数三分

    #include <bits/stdc++.h>
    using namespace std;
    #define endl '
    '
    typedef double db;
    typedef long long LL;
    const db EPS = 1e-9;
    const int N = 2e5 + 100,INF = 1 << 31 - 1;
    int a[N],n;
    int f(int mid) {
        int res = 0;
        for(int i = 0;i < n; ++i) {
            res += (a[i] - mid) * (a[i] - mid);
        }
        return res;
    }
    int main() {
        ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
        int lans,rans;
        cin >> n;
        for(int i = 0;i < n; ++i) cin >> a[i];
        int l = 1,r = 100;
        while(l < r) {
            int lmid = l + (r - l) / 3;
            int rmid = r - (r - l) / 3;
            lans = f(lmid),rans = f(rmid);
            if(lans <= rans) r = rmid - 1;
            else l = lmid + 1;
        }
        cout << min(lans,rans) << endl;
        return 0;
    }
    

    D

    组合数取模,快速幂求逆元
    (ans = 2^n - 1 - C_{n}^{a} - C_{n}^{b})

    #include <bits/stdc++.h>
    using namespace std;
    #define endl '
    '
    const int mod = 1e9 + 7,N = 2e5 + 10;
    typedef long long LL;
    int qmi(int a,int b) {
        int res = 1 % mod;
        while(b) {
            if(b & 1) res = (LL)res * a % mod;
            a = (LL)a * a % mod;
            b >>= 1;
        }
        return res;
    }
    void addmod(int &x,int y) {
        x += y;
        if(x >= mod) x -= mod;
        if(x < 0) x += mod;
    }
    int main() {
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
        int n,a,b,ans,s = 1;
        cin >> n >> a >> b;
        ans = qmi(2,n);
        addmod(ans, -1);
        for(int i = 1;i <= b; ++i) {
            s = (LL)s * (n - i + 1) % mod;
            s = (LL)s * qmi(i,mod - 2) % mod;
            if(i == a) addmod(ans,-s);
            if(i == b) addmod(ans,-s);
        }
        cout << ans << endl;
        return 0;
    }
    
  • 相关阅读:
    dedecms自定义表单提交获取时间跟ip地址
    JQuery购物车多物品数量的加减+总价计算
    jquery手机触屏滑动拼音字母城市选择器代码
    js实现图片上传实时显示
    js实现发送验证码倒计时效果
    JS 仿支付宝input文本输入框放大组件
    js实现倒计时效果
    jquery统计输入文字的个数并对其进行判断
    【Linux】Linux系统安全设置
    java泛型(generics)
  • 原文地址:https://www.cnblogs.com/lukelmouse/p/12546331.html
Copyright © 2011-2022 走看看