• Codeforces Round #565 (div. 3)


    水题他又lei了。

    题目链接:https://codeforces.com/contest/1176


    A:

    暴力。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int q;
    21 ll n;
    22 
    23 int main() {
    24     cin >> q;
    25     while (q--) {
    26         cin >> n; int ans = 0, flag = 1;
    27         while (n != 1) {
    28             if (n % 5 == 0) {
    29                 n = n / 5 * 4, ans++; continue;
    30             } else if (n % 3 == 0) {
    31                 n = n / 3 * 2, ans++; continue;
    32             } else if (n % 2 == 0) {
    33                 n /= 2, ans++; continue;
    34             } else {
    35                 flag = 0;
    36                 break;
    37             }
    38         }
    39         if (flag) cout << ans << endl; else puts("-1");
    40     }
    41     return 0;
    42 }
    View Code

    B:

    仔细点就可以了。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int t, n;
    21 
    22 int main() {
    23     scanf("%d", &t);
    24     while (t--) {
    25         int a = 0, b = 0, c = 0;
    26         scanf("%d", &n);
    27         while (n--) {
    28             int x; scanf("%d", &x);
    29             if (x % 3 == 0) a++;
    30             else if (x % 3 == 1) b++;
    31             else if (x % 3 == 2) c++;
    32         }
    33         int ans = a, tmp = min(b, c);
    34         ans += tmp, b -= tmp, c -= tmp;
    35         ans += b / 3, ans += c / 3;
    36         printf("%d
    ", ans);
    37     }
    38     return 0;
    39 }
    View Code

    C:

    次数统计即可。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 5e5 + 10;
    21 int n, a[7], ans = 0;
    22 
    23 int main() {
    24     scanf("%d", &n);
    25     rep1(i, 1, 6) a[i] = 0;
    26     rep1(i, 1, n) {
    27         int x; scanf("%d", &x);
    28         if (x == 4) a[1]++;
    29         else if (x == 8)
    30                 if (a[1] > a[2])a[2]++; else ans++;
    31         else if (x == 15)
    32                 if (a[2] > a[3]) a[3]++; else ans++;
    33         else if (x == 16)
    34                 if (a[3] > a[4]) a[4]++; else ans++;
    35         else if (x == 23)
    36                 if (a[4] > a[5]) a[5]++; else ans++;
    37         else if (a[5] > a[6]) a[6]++; else ans++;
    38     }
    39     int minn = int_inf;
    40     rep1(i, 1, 6) minn = min(minn, a[i]);
    41     rep1(i, 1, 6) ans += a[i] - minn;
    42     printf("%d
    ", ans);
    43     return 0;
    44 }
    View Code

    D:

    按照题目的意思,数组b中的所有合数必然在原有的数组a中。剩下的质数也就很好处理了。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 2750131;
    21 int vis[maxn + 5], p[maxn + 5], cnt[2 * maxn + 5], a[maxn + 5], b[2 * maxn + 5];
    22 int tot = 1;
    23 
    24 void getPrime() {
    25     memset(vis, 0, sizeof(vis));
    26     for (int i = 2; i <= maxn; i++) {
    27         if (vis[i] == 0)
    28             p[tot++] = i;
    29         for (int j = 1; j <= maxn && i * p[j] <= maxn; j++) {
    30             vis[i * p[j]] = 1;
    31             if (i % p[j] == 0)
    32                 break;
    33         }
    34     }
    35 }
    36 
    37 bool cmp(int a, int b) {
    38     return a > b;
    39 }
    40 
    41 int main() {
    42     int n;
    43     getPrime();
    44     scanf("%d", &n);
    45     memset(cnt, 0, sizeof(cnt));
    46     for (int i = 0; i < 2 * n; i++) {
    47         scanf("%d", &b[i]);
    48         cnt[b[i]]++; // count times
    49     }
    50     int q = 0;
    51     sort(b, b + 2 * n, cmp);
    52     for (int i = 0; i < 2 * n; i++) {
    53         if (cnt[b[i]] == 0)continue;
    54         if (vis[b[i]]) // if b[i] is not a prime, it must be in array a
    55             for (int j = 1; j < tot; j++)
    56                 if (b[i] % p[j] == 0) {
    57                     int t = b[i] / p[j]; // t is the greatest divisor
    58                     a[q++] = b[i];  
    59                     cnt[b[i]]--;
    60                     cnt[t]--;
    61                     break;
    62                 }
    63     }
    64     for (int i = 2; i <= maxn; i++)
    65         while (cnt[i]) {
    66             a[q++] = i;
    67             cnt[i]--;
    68             cnt[p[i]]--;
    69         }
    70     for (int i = 0; i < n; i++) printf("%d ", a[i]);
    71     puts("");
    72     return 0;
    73 }
    View Code

    E:

    说白了就是一个DFS染色的事情。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(half,b) sort(half+1,half+1+b)
     9 #define rep1(i,half,b) for(int i=half;i<=b;++i)
    10 #define rep0(i,half,b) for(int i=half;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson curpos<<1
    15 #define rson curpos<<1|1
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 2e5 + 10;
    21 int n, m, vis[maxn];
    22 vector<int>adj[maxn], ans, ans1;
    23 
    24 void dfs(int x, int depth) {
    25     if (depth % 2 == 0) ans.pb(x);
    26     else ans1.pb(x);
    27     vis[x] = 1;
    28     rep0(i, 0, adj[x].size()) {
    29         int y = adj[x][i];
    30         if (!vis[y]) dfs(y, depth + 1);
    31     }
    32 }
    33 
    34 int main() {
    35     int t; scanf("%d", &t);
    36     while (t--) {
    37         ans.clear(); ans1.clear();
    38         scanf("%d%d", &n, &m);
    39         int half = n / 2;
    40         rep1(i, 1, n) {
    41             vis[i] = 0; adj[i].clear();
    42         }
    43         rep1(i, 1, m) {
    44             int x, y; scanf("%d%d", &x, &y);
    45             adj[x].pb(y); adj[y].pb(x);
    46         }
    47         dfs(1, 0);
    48         if (ans.size() <= half) {
    49             printf("%d
    ", (int)ans.size());
    50             for (auto i : ans) printf("%d ", i);
    51         } else {
    52             printf("%d
    ", (int)ans1.size());
    53             for (auto i : ans1) printf("%d ", i);
    54         }
    55         puts("");
    56     }
    57     return 0;
    58 }
    View Code

    F:

    dp跑路……

  • 相关阅读:
    完美解决IE8有两个进程的问题
    用ccproxy + stunnel做个加密代理
    Hyper-V 共享式网络链接 端口映射
    NET Framework 4.0的安装失败处理
    c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 .
    设置IE8 多个Table只产生一个进程
    SSH Secure Shell Client中文乱码的解决办法
    OOD设计模式
    MVC设计模式
    乐观锁和悲观锁
  • 原文地址:https://www.cnblogs.com/JHSeng/p/11184549.html
Copyright © 2020-2023  润新知