zoukankan      html  css  js  c++  java
  • CodeForces Round #565 Div.3

    A. Divide it!

    #include <bits/stdc++.h>
    using namespace std;
     
    int N;
    map<long long, int> mp;
     
    void init() {
        mp.clear();
        long long u[62];
        u[1] = 2;
        mp[2] = 1;
        
        for(int i = 2; i <= 62; i ++) {
            u[i] = 2 * u[i - 1];
            mp[u[i]] = i;
        }
        
    }
     
    int main() {
        scanf("%d", &N);
        init();
        while(N --) {
            long long x;
            scanf("%lld", &x);
            long long ans = 0;
            if(x == 1) ans = 0;
            else {
                    while(x % 3 == 0) {
                        x /= 3;
                        x *= 2;
                        ans ++;
                    }
                            
                    while(x % 5 == 0) {
                        x /= 5;
                        x *= 4;
                        ans ++;
                    }
                
                if(!mp[x]) ans = -1;                
                else ans += mp[x];
                            
            }
             
            printf("%lld
    ", ans);
            
        }
        return 0;
    }
    View Code

    B. Merge it!

    #include <bits/stdc++.h>
    using namespace std;
     
    const int maxn = 110;
    int T;
    int a[maxn];
     
    int main() {
        scanf("%d", &T);
        while(T --) {
            int N;
            scanf("%d", &N);
            int one = 0, two = 0, ans = 0;
            for(int i = 1; i <= N; i ++) {
                scanf("%d", &a[i]);
                if(a[i] % 3 == 0) ans ++;
                if(a[i] % 3 == 1) one ++;
                if(a[i] % 3 == 2) two ++;
            }
                    
            if(one == two) ans += one;
            else if(one > two) {
                one -= two;
                ans += two;
                ans += (one / 3);
            } else {
                two -= one;
                ans += one;
                ans += (two / 3);
            }
            
            printf("%d
    ", ans);
            
        }
        return 0;
    }
    View Code

    C. Lose it!

    #include <bits/stdc++.h>
    using namespace std;
     
    const int maxn = 5e5 + 10;
    int N;
    int a[maxn], pos[maxn];
    int num[7] = {0, 4, 8, 15, 16, 23, 42};
     
    int main() {
        
        memset(pos, 0, sizeof(pos));
        
        scanf("%d", &N);
        for(int i = 1; i <= N; i ++) {
            scanf("%d", &a[i]);
            
            int t = lower_bound(num + 1, num + 1 + 6, a[i]) - num;
            
            if(t == 1) ++ pos[1];
            else {
                if(pos[t - 1] > 0) {
                    -- pos[t - 1];
                    ++ pos[t];
                }
            }
            
        }
        
        printf("%d
    ", N - 6 * pos[6]);
        
        return 0;
    }
    View Code

    E. Cover it!

    #include <bits/stdc++.h>
    using namespace std;
     
    const int maxn = 2e5 + 10;
    int T;
    int N, M;
    int vis[maxn];
    vector<int> ans[2];
    vector<int> v[maxn];
     
    void dfs(int st, int cnt, int lev) {
        vis[st] = 1;
        ans[lev].push_back(st);
        for(int i = 0; i < v[st].size(); i ++) {
            if(vis[v[st][i]]) continue;
            vis[v[st][i]] = 1;
            dfs(v[st][i], cnt + 1, !lev);
        }
    }
     
    int main() {
        scanf("%d", &T);
        while(T --) {
            scanf("%d%d", &N, &M);
     
            for(int i = 1; i <= N; i ++)
                v[i].clear(), vis[i] = 0;
     
            ans[0].clear(), ans[1].clear();
     
            for(int i = 0; i < M; i ++) {
                int st, en;
                scanf("%d%d", &st, &en);
                v[st].push_back(en);
                v[en].push_back(st);
            }
     
            dfs(1, 1, 0);
     
            int temp;
            printf("%d
    ", min(ans[0].size(), ans[1].size()));
            ans[0].size() < ans[1].size() ? temp = 0 : temp = 1;
     
            for(int i = 0; i < ans[temp].size(); i ++)
                printf("%d%s", ans[temp][i], i != ans[temp].size() - 1 ? " " : "
    ");
        }
        return 0;
    }
    View Code

    E 每次初始化的时候 vis 不能 memset 会 TLE 在 15 组样例(两次!!)!!!

    好久好久才更了一组 最近可能是有点忙?还是不能丢下当初辛辛苦苦学了那么久的东西 熬过去每一段觉得筋疲力尽的日子就会好起来了 

    也许我知道现在还不是最糟糕 那就等 down 到谷底再触底反弹的瞬间 8!

  • 相关阅读:
    (全国多校重现赛一) H Numbers
    (全国多校重现赛一)E-FFF at Valentine
    (全国多校重现赛一)B-Ch's gifts
    (全国多校重现赛一)A-Big Binary Tree
    UVA-10391 Compoud Words
    HDU-1027Ignatius and princess II
    CodeForces-501B
    UVA-136Ugly numbers
    UVA-101
    UVA-10474
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/11335770.html
Copyright © 2011-2022 走看看