• Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)


    __Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) __

    A. Forgetting Things

    • 思路:(a)(b)相等或者(a + 1 = b)或者(a = 9) (b = 1)才可

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    int a, b, x;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> a >> b;
        if (a == 9 && b == 1){
            cout << "9 10
    ";
            return 0;
        }
        if (a == b)
            cout << a << "0 " << b << "1
    ";
        else if (a + 1 == b)
            cout << a << " " << b << "
    ";
        else
            cout << -1 << "
    ";
        return 0;
    }
    

    B. TV Subscriptions

    • 思路:滑动窗口 辣鸡评测鸡 昨晚上交system test给我t了22 结果我早上交相同的代码就过了

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    const int N = 2e5 + 10;
    const int M = 1e6 + 10;
    const int INF = 0x3f3f3f3f;
    
    int t, n, k, d, min_, ans;
    int a[N], b[M];
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> t;
        while(t -- ){
            memset(b, 0, sizeof(b));
            cin >> n >> k >> d;
            ans = 0;
            for (int i = 1; i <= n; i ++ )
                cin >> a[i];
            for (int i = 1; i <= d; i ++ )
                if (b[a[i]] ++ == 0)
                    ans ++ ;
            min_ = ans;
            for (int i = d + 1; i <= n; i ++ ){
                if (( -- b[a[i - d]]) == 0)
                    ans -- ;
                if ((b[a[i]] ++ ) == 0)
                    ans ++ ;
                if (ans < min_)
                    min_ = ans;
            }
            cout << min_ << "
    ";
        }
        return 0;
    }
    

    C. p-binary

    • 思路:从1开始枚举ans 统计(n - ans * p)二进制中一的个数即可
      昨晚上没想到__builtin_popcountll_ 睡醒早上才想到
    • AC代码

    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
     
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
     
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
     
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
     
    ll n, p, ans = 1;
     
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n >> p;
        while (n - ans * p > 0){
            if (__builtin_popcountll(n - ans * p) <= ans){
                if (n - ans * p >= ans){
                    cout << ans << "
    ";
                    return 0;
                }
            }
            ans ++ ;
        }
        cout << "-1
    ";
        return 0;
    }
    

    D. Power Products

    • 思路:照着官方题解写的 先将(a)唯一分解定理 对于每一项(bi ^ ki) 当且仅当(ki % k == 0)时才对结果有贡献 最后统计下即可

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll Pow(ll a, ll b){
        ll res = 1;
        while (b){
            if (b & 1)
                res *= a;
            a *= a;
            b >>= 1;
        }
        return res;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    const int N = 1e5 + 10;
    
    int n, k, a;
    ll ans;
    map<vector<pair<int, int> >, int > mp;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n >> k;
        for (int i = 1; i <= n; i ++ ){
            vector<pair<int, int> > vec, res;
            cin >> a;
            for (int b = 2; b * b <= a; b ++ ){
                int k_ = 0;
                while (a % b == 0){
                    k_ ++ ;
                    a /= b;
                }
                if (k_ % k)
                    vec.push_back(make_pair(b, k_ % k));
            }
            if (a > 1)
                vec.push_back(make_pair(a, 1));
            for (int j = 0; j < vec.size(); j ++ )
                res.push_back(make_pair(vec[j].first, k - vec[j].second));
            ans += mp[res];
            mp[vec] ++ ;
        }
        cout << ans << "
    ";
        return 0;
    }
    
  • 相关阅读:
    .NET 6.0 —— 网络监视器 (TODO)
    Google adwords api —— report & AWQL
    Linux 镜像更新 为国内镜像源 for debian
    优化代码 —— 二八法则 & 编完代码,再优化
    鳥哥的 Linux 私房菜 ——— 第十八章、 服务的防火墙管理 xinetd, TCP Wrappers(3)
    端口号port 是什么
    aptget的install、update、upgrade的区别(转发)
    Google ads api —— github
    .net 6.00 —— record 类型 (TODO)
    Compiled models —— .NET Core 6.0
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11747034.html
Copyright © 2020-2023  润新知