• Codeforces Round #647 (Div. 2)


    离谱前4题简单, 后两题难的离谱, E就过了150, F过了1个,

    真就都卡在E做不下去

    A

    水题

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        for (cin >> _; _; --_)
        {
            ll a, b; cin >> a >> b;
            if (a > b) swap(a, b);
            if (a == b) { cout << 0 << '
    '; continue; }
            if (b % a) {cout << -1 << '
    '; continue; } 
            ll c = b / a;
            int ans = 0;
            while (c % 8 == 0) ++ans, c /= 8;
            while (c % 4 == 0) ++ans, c /= 4;
            while (c % 2 == 0) ++ans, c /= 2;
            if (ans == 0 || c != 1) ans = -1;
            cout << ans << '
    ';       
        }
        return 0;
    }
    

    B

    暴力

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    int a[N], b[N];
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        for (cin >> _; _; --_)
        {
            cin >> n;
            memset(b, 0, sizeof b);
            rep (i, 1, n) cin >> a[i], b[a[i]] = 1;
     
            int ans = 1, fl = 0;
            for (bool flag = 0; !flag && ans <= 1024; ++ans, fl = flag)
            {
                flag = 1;
                rep (i, 1, n)
                    if (b[a[i] ^ ans] == 0) { flag = 0; break; }
            }
            if (fl) cout << ans - 1 << '
    ';
            else cout << -1 << '
    ';
        }
        return 0;
    }
    

    C

    拆分二进制,先处理一下

    然后从高位到低位,拆一算答案

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    ll s[65], f[65];
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        s[0] = f[0] = 1;
        rep (i, 1, 60) s[i] = s[i - 1] << 1, f[i] = (f[i - 1] << 1) + i + 1;
        for (cin >> _; _; --_)
        {
            ll a, ans = 0; cin >> a;
            while (a)
            {
                if (a == 1) { ans += 1; break; }
                int idx = 0;
                while (s[idx] <= a) ++idx;
                //cout << idx << ' ' << s[idx - 1] << ' ' << f[idx - 2]  << '
    ';
                ans += f[idx - 2] + idx; a -= s[idx - 1];
            }
            cout << ans << '
    ';
        }
        return 0;
    }
    

    D

    模拟完事

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 5e5 + 5;
     
    int n, m, _, k;
    int h[N], to[N << 1], ne[N << 1], tot;
    int a[N], ans[N], s[N], v[N];
     
    void add(int u, int v)
    {
        ne[++tot] = h[u]; h[u] = tot; to[tot] = v;
    }
     
    bool cmp(int x, int y)
    {
        return a[x] < a[y];
    }
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        cin >> n >> m;
        rep (i, 1, m)
        {
            int u, v; cin >> u >> v;
            add(u, v); add(v, u);
        }
        rep(i, 1, n) cin >> a[i], s[i] = i;
     
        sort(s + 1, s + 1 + n, cmp);
     
        bool flag = 0;
        rep (i, 1, n)
        {
            //cout << i << ' ' << s[i] << ' ' << a[s[i]] << '
    ';
            int x = s[i], c = 0;
            for (int j = h[x]; j; j = ne[j])
            {
                int y = to[j];
                if (a[y] == a[x]) { flag = 1; break; }
                if (a[y] < a[x] && v[a[y]] == 0) { v[a[y]] = 1, ++c; }
            }
            //if (i == 3) cout << flag << ' ' << c << '
    ';
            if (flag || c < a[x] - 1) { flag = 1; break; }
            ans[i] = s[i];
            rep (j, 1, a[x] - 1) v[j] = 0;
        }
     
        if (flag) cout << -1;
        else  rep (i, 1, n) cout << ans[i] << ' ';
        return 0;
    }
    
  • 相关阅读:
    ffplay源码分析05 ---- 音频重采样
    ffplay源码分析04 ---- 音频输出
    RTMP协议01 ---- 握手
    ffplay源码分析03 ---- 音频解码线程
    ffplay源码分析03 ---- 视频解码线程
    ffplay源码分析02 ---- 数据读取线程
    注解方式实例化Java类
    构造方法与setter方法
    ②初识spring
    分布式编程
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/13048049.html
Copyright © 2020-2023  润新知