• Codeforces Round #597 (Div. 2)


    Codeforces Round #597 (Div. 2)

    A. Good ol' Numbers Coloring

    • 思路:水题

    • 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 t, a, b;
    
    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 -- ){
            cin >> a >> b;
            if (gcd(a, b) == 1)
                cout << "Finite
    ";
            else
                cout << "Infinite
    ";
        }
        return 0;
    }
    

    B. Restricted RPS

    • 思路:照着题意模拟

    • 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 t, n, a, b, c, cr, cp, cs, cnt, pos;
    string s, ans;
     
    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 -- ){
            ans.clear();
            cr = cp = cs = 0;
            cin >> n >> a >> b >> c >> s;
            for (int i = 0; i < n; i ++ ){
                if (s[i] == 'R')
                    cr ++ ;
                else if (s[i] == 'P')
                    cp ++ ;
                else
                    cs ++ ;
            }
            cnt = min(a, cs) + min(b, cr) + min(c, cp);
            if (cnt * 2 < n){
                cout << "NO
    ";
                continue;
            }
            for (int i = 0; i < n; i ++ ){
                if (s[i] == 'R' && b){
                    ans += 'P';
                    b -- ;
                }
                else if (s[i] == 'P' && c){
                    ans += 'S';
                    c -- ;
                }
                else if (s[i] == 'S' && a){
                    ans += 'R';
                    a -- ;
                }
                else
                    ans += '#';
            }
            for (int i = 0; i < n; i ++ ){
                if (ans[i] == '#'){
                    if (a){
                        ans[i] = 'R';
                        a -- ;
                        continue;
                    }
                    if (b){
                        ans[i] = 'P';
                        b -- ;
                        continue;
                    }
                    if (c){
                        ans[i] = 'S';
                        c -- ;
                        continue;
                    }
                }
            }
            cout << "YES
    " << ans << "
    ";
        }
        return 0;
    }
    

    C. Constanze's Machine

    • 思路:dp 类似于斐波拉契数列

    • 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 = 1e5 + 10;
    const int mod = 1e9 + 7;
    
    int len;
    int dp[N] = {1, 1};
    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;
        len = s.length();
        for (auto it: s){
            if (it == 'w' || it == 'm'){
                cout << "0
    ";
                return 0;
            }
        }
        for (int i = 2; i <= len; i ++ ){
            dp[i] = dp[i - 1];
            if (s[i - 1] == s[i - 2] && (s[i - 1] == 'u' || s[i - 1] == 'n'))
                dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
        }
        cout << dp[len] << "
    ";
        return 0;
    }
    

    D. Shichikuji and Power Grid

    • 思路:最小生成树

    • 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 = 2010;
    
    struct node{
        ll x, y, c, k, vis, change;
    }num[N];
    
    struct E{
        int fir, sec;
    }e[N];
    
    int n, tmp, c1, c2;
    int p[N];
    ll ans;
    
    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 >> num[i].x >> num[i].y;
        for (int i = 1; i <= n; i ++ ){
            cin >> num[i].c;
            num[i].vis = num[i].change = 0;
        }
        for (int i = 1; i <= n; i ++ )
            cin >> num[i].k;
        num[0].c = 1 << 30;
        for (int i = 1; i <= n; i ++ ){
            tmp = 0;
            for (int j = 1; j <= n; j ++ )
                if (num[j].c < num[tmp].c && !num[j].vis)
                    tmp = j;
            num[tmp].vis = 1;
            ans += num[tmp].c;
            if (num[tmp].change){
                c2 ++ ;
                e[c2].fir = tmp;
                e[c2].sec = num[tmp].change;
            }
            else
                p[ ++ c1] = tmp;
            for (int j = 1; j <= n; j ++ ){
                if (num[j].c > (abs(num[j].x - num[tmp].x) + abs(num[j].y - num[tmp].y)) * (num[j].k + num[tmp].k)){
                    num[j].c = (abs(num[j].x - num[tmp].x) + abs(num[j].y - num[tmp].y)) * (num[j].k + num[tmp].k);
                    num[j].change = tmp;
                }
            }
        }
        cout << ans << "
    " << c1 << "
    ";
        for (int i = 1; i <= c1; i ++ )
            cout << p[i] << " ";
        cout << "
    " << c2 << "
    ";
        for (int i = 1; i <= c2; i ++ )
            cout << e[i].fir << " " << e[i].sec << "
    ";
        return 0;
    }
    
  • 相关阅读:
    【机器学习】算法原理详细推导与实现(一):线性回归
    《0~3岁孩子的 正面管教》——备忘
    马歇尔·卢森堡《非暴力沟通》——备忘
    李笑来《财富自由之路》——备忘
    select、poll、epoll之间的区别总结[整理]
    堆和栈区别
    Linux 文件系统剖析
    Inside The C++ Object Model(五)
    Inside The C++ Object Model(四)
    Inside The C++ Object Model(三)
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11801543.html
Copyright © 2020-2023  润新知