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\n";
    else
        cout << "NO\n";
    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\n";
        else if (s[0] != '0' && k == 0)
            cout << s << "\n";
        else
            cout << s << "\n";
        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 << "\n";
    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 << "\n";
        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 << "\n";
    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 << "\n";
    return 0;
}

原文地址:https://www.cnblogs.com/Misuchii/p/11801521.html

时间: 2024-08-16 07:52:46

Codeforces Round #588 (Div. 2)的相关文章

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

链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1≤a≤b≤6, there is exactly one domino with a dots on one half and b dots on th

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

链接: https://codeforces.com/contest/1230/problem/D 题意: Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. L

Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)

链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached 100 million subscribers. In order to celebrate this, he posted a video with an interesting problem

A. Dawid and Bags of Candies ( Codeforces Round #588 (Div. 2) )

Dawid has four bags of candies. The ii-th of them contains aiai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount o

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

Ania has a large integer SS. Its decimal representation has length nn and doesn't contain any leading zeroes. Ania is allowed to change at most kk digits of SS. She wants to do it in such a way that SS still won't contain any leading zeroes and it'll

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

Marcin is a coach in his university. There are nn students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. Let's focus on the students. They are indexed with int

Codeforces Round #588 (Div. 1)

Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数$-1$的时候放队列里,每一次取队头更新其他人diss的人数. code B sol 一个结论:对于序列$a_1,a_2,...,a_n$,其前缀$gcd$数量不超过$log_2a_i$种.证明考虑从前往后计算前缀$gcd$,那么从第$i-1$个$gcd$到第$i$个$gcd$,数值要么不变要么至少

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿