• Codeforces Round #582 (Div. 3)


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


    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=110;
    21 int n,a[maxn];
    22 
    23 int main() {
    24     scanf("%d",&n);
    25     int aa=0,bb=0;
    26     rep1(i,1,n){
    27         int x; scanf("%d",&x);
    28         if (x&1) aa++; else bb++;
    29     }
    30     printf("%d
    ",min(aa,bb));
    31     return 0;
    32 }
    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 const int maxn = 150010;
    21 int n, a[maxn];
    22 
    23 int main() {
    24     int t; scanf("%d", &t);
    25     while (t--) {
    26         scanf("%d", &n);
    27         rep1(i, 1, n) scanf("%d", &a[i]);
    28         stack<int>s;
    29         while (!s.empty()) s.pop();
    30         s.push(a[n]);
    31         int ans = 0;
    32         for (int i = n - 1; i > 0; i--) {
    33             if (a[i] > s.top()) ans++;
    34             else if (a[i] < s.top()) s.push(a[i]);
    35         }
    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 int main() {
    21     int q; scanf("%d", &q);
    22     while (q--) {
    23         ll n, m; scanf("%lld%lld", &n, &m);
    24         if (n < m) {
    25             puts("0");
    26             continue;
    27         }
    28         if (n == m) {
    29             printf("%lld
    ", m % 10);
    30             continue;
    31         }
    32         ll len = n / m, tmp = m, sum = 0;
    33         set<int>s; s.clear();
    34         while (!s.count(tmp % 10)) {
    35             s.insert(tmp % 10);
    36             tmp += m;
    37         }
    38         tmp -= m;
    39         for (auto i : s) sum += i;
    40         int round = s.size();
    41         sum = len / round * sum;
    42         for (ll i = len / round * tmp + m; i <= n; i += m) {
    43             sum += i % 10;
    44         }
    45         printf("%lld
    ", sum);
    46     }
    47     return 0;
    48 }
    View Code

    D:

    计算每个数对“比它小的能除2到达的数”的贡献,然后每个数取除2次数前k小即可。

     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 = 2e5 + 10;
    21 int n, k, ans = int_inf;
    22 vector<int>v[maxn];
    23 
    24 int main() {
    25     scanf("%d%d", &n, &k);
    26     rep1(i, 1, n) {
    27         int x, cnt = 0; scanf("%d", &x);
    28         do {
    29             v[x].pb(cnt);
    30             x >>= 1;
    31             cnt++;
    32         } while (x);
    33     }
    34     for (int i = 0; i < maxn; i++) {
    35         if ((int)v[i].size() < k) continue;
    36         sort(v[i].begin(), v[i].end());
    37         int tot = 0;
    38         for (int j = 0; j < k; j++) tot += v[i][j];
    39         ans = min(ans, tot);
    40     }
    41     printf("%d
    ", ans);
    42     return 0;
    43 }
    View Code

    E:

    显然不可能无解,只有两种构造方式,验证即可。

     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 = 3e5 + 10;
    21 int n, pos[3] = {0, 1, 2};
    22 char s[4], t[4], ans[maxn];
    23 
    24 int check() {
    25     for (int i = 1; i < 3 * n; i++) {
    26         if (ans[i - 1] == s[0] && ans[i] == s[1]) return 0;
    27         if (ans[i - 1] == t[0] && ans[i] == t[1]) return 0;
    28     }
    29     return 1;
    30 }
    31 
    32 int main() {
    33     scanf("%d", &n);
    34     scanf("%s", s);
    35     scanf("%s", t);
    36     puts("YES");
    37     do {
    38         int res = 0;
    39         for (int k = 0; k < 3; k++)
    40             for (int i = 0; i < n; i++)
    41                 ans[res++] = 'a' + pos[k];
    42         if (check()) {
    43             printf("%s
    ", ans);
    44             return 0;
    45         }
    46     } while (next_permutation(pos, pos + 3));
    47     do {
    48         int res = 0;
    49         for (int i = 0; i < n; i++)
    50             for (int k = 0; k < 3; k++)
    51                 ans[res++] = 'a' + pos[k];
    52         if (check()) {
    53             printf("%s
    ", ans);
    54             return 0;
    55         }
    56     } while (next_permutation(pos, pos + 3));
    57     return 0;
    58 }
    View Code
  • 相关阅读:
    汇编讲解(上)--逆向开发
    两数之和 II
    解析器模式--设计模式
    访问者模式--设计模式
    命令模式--设计模式
    ccf-201512-2 消除类游戏
    ccf-201503-2 数字排序
    移动端兼容和适配问题
    ccf-201409-2 画图
    ccf-201409-3 字符串匹配
  • 原文地址:https://www.cnblogs.com/JHSeng/p/11437721.html
Copyright © 2020-2023  润新知