• codeforces 1230 div2


    C

    给一个图,并且在边上放上多米诺骨牌,使得每个多米诺骨牌指向的顶点的数字是一致的,并且每种骨牌只能用一种。问最多能够覆盖多少条边。
    先生成每一个点指向的数字,然后判断就好了。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<bitset>
    
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    #define pb(x) push_back(x)
    #define cls(x, val) memset(x, val, sizeof(x))
    #define fi first
    #define se second
    #define mp(x, y) make_pair(x, y)
    #define inc(i, l, r) for(int i=l; i<=r; i++)
    const int inf = 0x3f3f3f3f;
    const int maxn = 2000+10;
    int n, m;
    int l[maxn], r[maxn];
    bool vis[11][11];
    //数组开小了,然后就会不断的覆盖。。。
    int domi[8];
    int ans;
    
    void check(){
        int tot = 0;
        cls(vis, 0);
    
        for(int i=1; i<=m; i++){
            int a = domi[l[i]], b=domi[r[i]];
            if(a>b) swap(a, b);
            if(!vis[a][b]){
                vis[a][b] = true;
                tot++;
            }
        }
    
        if(tot>ans) ans = tot;
        //cout<<"---"<<ans<<endl;
    }
    
    void dfs(int dep){
        if(dep>n){
            check();
            return ;
        }
        for(int i=1; i<=6; i++){
            domi[dep] = i;
            dfs(dep+1);
        }
    
    }
    
    int main(){
        ios::sync_with_stdio(false);
        cin>>n>>m;
        ans = 0;
        for(int i=1; i<=m; i++){
            cin>>l[i]>>r[i];
        }
        dfs(1);
        cout<<ans<<endl;
    
        return 0;
    }
    
    

    D

    找两个及以上的人去覆盖就可以了。
    时间复杂度(O(n^2))

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<bitset>
    #include <unordered_map>
    
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    #define pb(x) push_back(x)
    #define cls(x, val) memset(x, val, sizeof(x))
    #define fi first
    #define se second
    #define mp(x, y) make_pair(x, y)
    #define inc(i, l, r) for(int i=l; i<=r; i++)
    const int inf = 0x3f3f3f3f;
    const int maxn = 7000+10;
    int n;
    int idx;
    ll a[maxn];
    ll c[maxn];
    ll b[maxn];
    int val[maxn];
    ll ans = 0;
    unordered_map<ll, int> num;
    
    int main(){
        ios::sync_with_stdio(false);
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
            num[a[i]]++;
            if(num[a[i]]>=2) {
                c[++idx] = a[i];
            }
        }
        for(int i=1; i<=n; i++) cin>>b[i];
        for(int i=1; i<=idx; i++){
            for(int j=1; j<=n; j++){
                //i覆盖了j
                if((c[i]&a[j]) == a[j]) val[j] = 1;
            }
        }
        for(int i=1; i<=n; i++) ans += (val[i]*b[i]);
        cout<<ans<<endl;
    
        return 0;
    }
    
    

    E

    有一个结论,若干个数字的gcd,不同的个数为(O(log(n)))的级别,使得这道题目的map的常数较小。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<bitset>
    #include <unordered_map>
    
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    #define pb(x) push_back(x)
    #define cls(x, val) memset(x, val, sizeof(x))
    #define fi first
    #define se second
    #define mp(x, y) make_pair(x, y)
    #define inc(i, l, r) for(int i=l; i<=r; i++)
    const int inf = 0x3f3f3f3f;
    const int maxn = 2e5+10;
    const int mod = 1e9+7;
    
    ll a[maxn];
    vector<int> G[maxn];
    int n;
    unordered_map<ll, int> mp[maxn];
    ll ans;
    
    void dfs(int u, int fa){
        for(auto &it:mp[fa]){
            //更新前面的节点到u节点的权值和。
            ll temp = __gcd(it.fi, a[u]);
            mp[u][temp]+=(it.se)%mod;
            ans = (ans + (temp*it.se%mod))%mod;
        }
        //更新自己到自己
        mp[u][a[u]]++;
        ans = (ans+a[u])%mod;
    
        for(auto &v:G[u]){
            if(v == fa) continue;
            dfs(v, u);
        }
    }
    
    int main(){
        ios::sync_with_stdio(false);
        cin>>n;
        for(int i=1; i<=n; i++) cin>>a[i];
        int u, v;
        for(int i=1; i<n; i++){
            cin>>u>>v;
            G[u].push_back(v), G[v].push_back(u);
        }
        dfs(1, 1);
    
        cout<<ans<<endl;
        return 0;
    }
    
    
  • 相关阅读:
    upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream
    当代免疫学小史-第一章(根据讲谈社Blue Backs系列2009年第一版第三次印刷版本翻译)
    微信小程序自定义tabbar解决方案(可用于解决tabbar跳转至分包页面问题)
    celery的使用
    分布式之数据库和缓存双写一致性方案解析
    opencv实战-全景图像拼接
    matplotlib+seaborn样式管理-学习整理
    matplotlib绘制3D图形
    matplotlib+seaborn图形绘制-学习整理
    opencv实战-文档扫描
  • 原文地址:https://www.cnblogs.com/babydragon/p/11577400.html
Copyright © 2020-2023  润新知