Codeforces Round #588 (Div. 2)

Posted misuchii

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于Codeforces Round #588 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #588 (Div. 2)

Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)

Codeforces Round #588 (Div. 1)

B. Ania and Minimizing (Codeforces Round #588 (Div. 2) )

Codeforces Round #588 (Div. 2) D. Marcin and Training Camp(思维)

D. Marcin and Training Camp ( Codeforces Round #588 (Div. 2) )