Codeforces Round #588 (Div. 2)

A

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
const int maxn = 1e6 + 10;
int main(){
    //freopen("/Users/chutong/ACM/data.in","r",stdin);
    //freopen("/Users/chutong/ACM/data.out","w",stdout);
    int a[10];
    a[1] = read();
    a[2] = read();
    a[3] = read();
    a[4] = read();
    LL sum = (LL)a[1] + a[2] + a[3] + a[4];
    for(int i=1; i<=4; i++){
        if (2*a[i] == sum){
            cout << "YES" << endl;
            return 0;
        }
        for(int j=1; j<=4; j++){
            if (i != j && 2*(a[i] + a[j]) == sum){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

 

B:

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
const int maxn = 1e6 + 10;
int main(){
    //freopen("/Users/chutong/ACM/data.in","r",stdin);
    //freopen("/Users/chutong/ACM/data.out","w",stdout);
    int n = read(),k = read();
    string s;
    cin >> s;
    if (n == 1 && k > 0){
        cout << 0 << endl;
        return 0;
    }
    int tag = 0;
    if (s[0] != '1' && k > 0){
        s[0] = '1';
        k--;
        tag = 1;
    }
    for(int i=1; i<n; i++){
        if (s[i] != '0' && k > 0){
            s[i] = '0';
            k--;
            if (k == 0) break;
        }
    }
    cout << s << endl;
    return 0;
}

 

C

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
    int f = 1, x = 0;char ch = getchar();
    while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
const int maxn = 8;
int n,m;
struct node
{
    int u,v;    
}p[maxn*maxn];
int id[maxn];
int mp[maxn][maxn];
int ans;
void dfs(int step){
    if (step == n + 1){
        memset(mp,0,sizeof(mp));
        int res = 0;
        // cout << step << ' ' << n << endl;
        // for(int i=1; i<=n; i++){
        //     cout << id[i] << ' ';
        // }
        // cout << endl;
        for(int i=1; i<=m; i++){
            if (!mp[id[p[i].u]][id[p[i].v]]){
                mp[id[p[i].u]][id[p[i].v]] = mp[id[p[i].v]][id[p[i].u]] = 1;
                // cout << id[p[i].u] << ' ' << id[p[i].v] << endl;
                res++;
            }
        }
        ans = max(ans,res);
        return; 
    }
    for(int i=1; i<=6; i++){
        id[step] = i;
        dfs(step+1);
    }
}
int main(){
    //freopen("/Users/chutong/ACM/data.in","r",stdin);
    //freopen("/Users/chutong/ACM/data.out","w",stdout);
    n = read(),m = read();
    for(int i=1; i<=m; i++){
        p[i].u = read();
        p[i].v = read();
    }
    dfs(1);
    cout << ans << endl;
    return 0;
}

 

D

#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn];
int used[maxn],b[maxn];
map<long long,int> mp;
vector<long long> v;
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++){
        scanf("%lld",&a[i]);
        mp[a[i]]++;
    }
    long long ans = 0;
    for(int i=1; i<=n; i++){
        scanf("%d",&b[i]);
        if (mp[a[i]] >= 2){
            ans += b[i];
            used[i] = 1;
            v.push_back(a[i]);
        }
    }
    for(int i=1; i<=n; i++){
        if (!used[i]){
            for(auto now : v){
                if (a[i] < now && ((a[i] | now) == now)){
                    ans += b[i];
                    break;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值