zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Ajax技术应用方面
    关于tomcat环境配置的疑惑(tomcat未进行任何环境配置仍成功显示welcome页面)
    jsp中动态include与静态include的区别
    简单说说tomcat7.0的配置
    传统开发模式与Ajax开发模式的区别
    认识Ajax
    tomcat与jdk的关系
    org.hibernate.TransactionException: nested transactions not supported
    解读Tomcat7.0的startup.bat批处理命令
    forward和redirect的区别
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11801521.html
Copyright © 2011-2022 走看看