zoukankan      html  css  js  c++  java
  • Codeforces Round #586 (Div. 1 + Div. 2)

    Codeforces Round #586 (Div. 1 + Div. 2)

    A. Cards

    • 思路:水题

    • 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 n, cnt1, cnt2;
    string s;
    vector<int> cnt(26);
    
    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 >> s;
        for (auto x: s)
            cnt[x - 'a'] ++ ;
        cnt1 = cnt['n' - 'a'];
        cnt2 = cnt['z' - 'a'];
        for (int i = 1; i <= cnt1; i ++ )
            cout << "1 ";
        for (int i = 1; i <= cnt2; i ++ )
            cout << "0 ";
        return 0;
    }
    

    B. Multiplication Table

    • 思路:(frac{a_xa_y * a_xa_z}{a_ya_z} = {a_x}^2)

    • 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 = 1e3 + 10;
    
    int n;
    ll ans[N];
    ll M[N][N];
    
    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;
        for (int i = 1; i <= n; i ++ )
            for (int j = 1; j <= n; j ++ )
                cin >> M[i][j];
        ans[1] = sqrt(M[1][2] * M[1][3] / M[2][3]);
        for (int i = 2; i <= n; i ++ )
            ans[i] = M[1][i] / ans[1];
        for (int i = 1; i < n; i ++ )
            cout << ans[i] << " ";
        cout << ans[n] << "
    ";
        return 0;
    }
    

    C. Substring Game in the Lesson

    • 思路:瞎猜搞出来的

    • 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;
    }
    
    char min_ = 'z';
    string s;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> s;
        for (int i = 0; i < s.length(); i ++ ){
            if (min_ < s[i])
                cout << "Ann
    ";
            else{
                min_ = s[i];
                cout << "Mike
    ";
            }
        }
        return 0;
    }
    

    D. Alex and Julian

    • 思路:参照dalao的思路 如果是二分图, 则不存在奇环,.
      考虑存在a,则有0->a, a->2a, 如果存在2a,则有0->2a,就存在奇环,如果有4a, 6a 也会存在奇环, 因为0->4a, 0->6a都属于同一边.
      考虑存在p, 有0->p, 同时可以存在, 3p, 5p, 考虑p的最高2的幂在p乘上一个奇数以后不会增加, 所以同时只能存在2的幂与p相等的值. 原文链接

    • 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 = 70;
    
    int n, m;
    ll b[N], x;
    vector<ll> a[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 >> n;
        for (int i = 1; i <= n; i ++ ){
            cin >> b[i];
            int tmp = 0;
            x = b[i];
            while (x % 2 == 0){
                x /= 2;
                tmp ++ ;
            }
            a[tmp].push_back(i);
        }
        m = -1;
        for (int i = 0; i <= 64; i ++ )
            if (m == -1 || a[m].size() < a[i].size())
                m = i;
        cout << n - a[m].size() << "
    ";
        for (int i = 0; i <= 64; i ++ )
            if (i != m)
                for (int j = 0; j < a[i].size(); j ++ )
                    cout << b[a[i][j]] << " ";
        return 0;
    }
    
  • 相关阅读:
    P2016 战略游戏(没有上司的舞会变式)
    P2014 [CTSC1997]选课(树上背包)
    P2015 二叉苹果树(树上背包)
    P1122 最大子树和(简单树形DP)
    P1505 [国家集训队]旅游(树链剖分)
    linux下的几个网络流量监控工具使用
    大数据场景下数据异构之 Mysql实时写入HBase(借助canal kafka SparkStreaming)
    基于Spark Streaming + Canal + Kafka对Mysql增量数据实时进行监测分析
    sqoop安装与使用
    MongoDB各系统上安装
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11887017.html
Copyright © 2011-2022 走看看