• Codeforces Round #588 (Div. 2)


    Codeforces Round #588 (Div. 2)

    A. Dawid and Bags of Candies

    • 思路:水题

    • 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[4];
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        for (int i = 0; i < 4; i ++ )
            cin >> a[i];
        sort(a, a + 4);
        if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3])
            cout << "YES
    ";
        else
            cout << "NO
    ";
        return 0;
    }
    

    B. Ania and Minimizing

    • 思路:模拟

    • 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, k, cnt;
    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 >> n >> k >> s;
        if (n == 1){
            if (s[0] != '0' && k == 1)
                cout << "0
    ";
            else if (s[0] != '0' && k == 0)
                cout << s << "
    ";
            else
                cout << s << "
    ";
            return 0;
        }
        if (s[0] != '1' && cnt < k){
            s[0] = '1';
            cnt ++ ;
        }
        for (int i = 1; i < n; i ++ ){
            if (cnt >= k)
                break;
            if (s[i] != '0'){
                s[i] = '0';
                cnt ++ ;
            }
        }
        cout << s << "
    ";
        return 0;
    }
    

    C. Anadi and Domino

    • 思路:按着题意做就行了

    • 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 = 10;
    const int INF = 0x3f3f3f3f;
    
    int n, m, a, b, ans, res;
    int mp[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 >> m;
        for (int i = 1; i <= m; i ++ ){
            cin >> a >> b;
            mp[a][b] = mp[b][a] = 1;
        }
        if (n <= 6){
            cout << m << "
    ";
            return 0;
        }
        ans = INF;
        for (int i = 1; i <= n; i ++ ){
            for (int j = i + 1; j <= n; j ++ ){
                res = 0;
                for (int k = 1; k <= n; k ++ )
                    if (mp[i][k] && mp[j][k])
                        res ++ ;
                ans = min(ans, res);
            }
        }
        cout << m - ans << "
    ";
        return 0;
    }
    

    D. Marcin and Training Camp

    • 思路:暴力把所有可以的搞出来 然后同时标记子集

    • 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 = 7010;
    
    ll n, ans;
    ll a[N], b[N];
    map<ll, ll> mp;
    set<ll> st;
    
    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 >> a[i];
            ++ mp[a[i]];
        }
        for (int i = 1; i <= n; i ++ )
            cin >> b[i];
        for (auto it: mp)
            if (it.second > 1)
                for (int i = 1; i <= n; i ++ )
                    if ((it.first | a[i]) == it.first)
                        st.insert(i);
        for (auto it: st)
            ans += b[it];
        cout << ans << "
    ";
        return 0;
    }
    
  • 相关阅读:
    servlet 项目 ,,启动没问题,,但是,一请求也面就报错误。。。。求解决。。。。。。。。。。。。。各种百度,都没解决了啊。。。。。急急急急急急急急急急急急急急急急急急
    js 表单不为空,数字长度验证
    cordova 安卓项目打包 release安装包
    Vue-cli构建项目, 组件中js代码引入图片路径问题
    Vue-cli 构建项目 的`.vue`组件中, scss中添加背景图路径问题
    解决 Cordova命令突然无法使用问题.
    VS Code 自用插件备份
    Cordova环境搭建
    前端渲染与后端渲染方式大体对比
    JavaScript-获取当前元素的相关元素或节点--方法总结
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11801521.html
Copyright © 2020-2023  润新知