• AtCoder Grand Contest 011 题解


    A - Airport Bus

    贪心,能取就取。

     1 //waz
     2 #include <bits/stdc++.h>
     3  
     4 using namespace std;
     5  
     6 #define mp make_pair
     7 #define pb push_back
     8 #define fi first
     9 #define se second
    10 #define ALL(x) (x).begin(), (x).end()
    11 #define SZ(x) ((int)((x).size()))
    12  
    13 typedef pair<int, int> PII;
    14 typedef vector<int> VI;
    15 typedef long long int64;
    16 typedef unsigned int uint;
    17 typedef unsigned long long uint64;
    18  
    19 #define gi(x) ((x) = F())
    20 #define gii(x, y) (gi(x), gi(y))
    21 #define giii(x, y, z) (gii(x, y), gi(z))
    22  
    23 int F()
    24 {
    25     char ch;
    26     int x, a;
    27     while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    28     if (ch == '-') ch = getchar(), a = -1;
    29     else a = 1;
    30     x = ch - '0';
    31     while (ch = getchar(), ch >= '0' && ch <= '9')
    32         x = (x << 1) + (x << 3) + ch - '0';
    33     return a * x;
    34 }
    35  
    36 const int N = 1e5 + 10;
    37  
    38 int n, c, k, t[N], ans;
    39  
    40 int main()
    41 {
    42     giii(n, c, k);
    43     for (int i = 1; i <= n; ++i) gi(t[i]);
    44     sort(t + 1, t + n + 1);
    45     for (int i = 1; i <= n; ++i)
    46     {
    47         int j;
    48         if (t[n] > t[i] + k) j = upper_bound(t + 1, t + n + 1, t[i] + k) - t - 1;
    49         else j = n;
    50         j = min(i + c - 1, j);
    51         i = j;
    52         ++ans;
    53     }
    54     printf("%d
    ", ans);
    55 }

    B - Colorful Creatures

    二分答案,直接判断即可。

     1 //waz
     2 #include <bits/stdc++.h>
     3  
     4 using namespace std;
     5  
     6 #define mp make_pair
     7 #define pb push_back
     8 #define fi first
     9 #define se second
    10 #define ALL(x) (x).begin(), (x).end()
    11 #define SZ(x) ((int)((x).size()))
    12  
    13 typedef pair<int, int> PII;
    14 typedef vector<int> VI;
    15 typedef long long int64;
    16 typedef unsigned int uint;
    17 typedef unsigned long long uint64;
    18  
    19 #define gi(x) ((x) = F())
    20 #define gii(x, y) (gi(x), gi(y))
    21 #define giii(x, y, z) (gii(x, y), gi(z))
    22  
    23 int F()
    24 {
    25     char ch;
    26     int x, a;
    27     while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    28     if (ch == '-') ch = getchar(), a = -1;
    29     else a = 1;
    30     x = ch - '0';
    31     while (ch = getchar(), ch >= '0' && ch <= '9')
    32         x = (x << 1) + (x << 3) + ch - '0';
    33     return a * x;
    34 }
    35  
    36 const int N = 1e5 + 10;
    37  
    38 int n;
    39  
    40 int a[N];
    41  
    42 bool check(int x)
    43 {
    44     int64 s = a[x];
    45     for (int j = 1; j <= n; ++j)
    46         if (x != j)
    47         {
    48             if (s * 2 >= a[j]) s += a[j];
    49             else return 0;
    50         }
    51     return 1;
    52 }

    C - Squared Graph

    把原图中孤立点、二分图和其它连通块分开考虑一下即可。

     1 //waz
     2 #include <bits/stdc++.h>
     3  
     4 using namespace std;
     5  
     6 #define mp make_pair
     7 #define pb push_back
     8 #define fi first
     9 #define se second
    10 #define ALL(x) (x).begin(), (x).end()
    11 #define SZ(x) ((int)((x).size()))
    12  
    13 typedef pair<int, int> PII;
    14 typedef vector<int> VI;
    15 typedef long long int64;
    16 typedef unsigned int uint;
    17 typedef unsigned long long uint64;
    18  
    19 #define gi(x) ((x) = F())
    20 #define gii(x, y) (gi(x), gi(y))
    21 #define giii(x, y, z) (gii(x, y), gi(z))
    22  
    23 int F()
    24 {
    25     char ch;
    26     int x, a;
    27     while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    28     if (ch == '-') ch = getchar(), a = -1;
    29     else a = 1;
    30     x = ch - '0';
    31     while (ch = getchar(), ch >= '0' && ch <= '9')
    32         x = (x << 1) + (x << 3) + ch - '0';
    33     return a * x;
    34 }
    35  
    36 const int N = 1e5 + 10, M = 1e5 + 10;
    37  
    38 int n, m;
    39  
    40 bool flag;
    41  
    42 VI edge[N];
    43  
    44 int co[N];
    45  
    46 int O, P, Q;
    47  
    48 void dfs(int i, int x)
    49 {
    50     co[i] = x;
    51     for (auto j : edge[i])
    52     {
    53         if (co[j])
    54         {
    55             if (co[j] != (co[i] ^ 1)) flag = 0;
    56         }
    57         else
    58         {
    59             dfs(j, x ^ 1);
    60         }
    61     }
    62 }
    63  
    64 int main()
    65 {
    66     gii(n, m);
    67     for (int i = 1; i <= m; ++i)
    68     {
    69         int u, v;
    70         gii(u, v);
    71         edge[u].pb(v);
    72         edge[v].pb(u);
    73     }
    74     for (int i = 1; i <= n; ++i)
    75     {
    76         if (!co[i])
    77         {
    78             if (!SZ(edge[i]))
    79             {
    80                 ++O;
    81                 continue;
    82             }
    83             flag = 1;
    84             dfs(i, 2);
    85             if (flag) ++Q;
    86             else ++P;
    87         }
    88     }
    89     long long ans = 2LL * O * n - 1LL * O * O + 1LL * P * P + 2LL * P * Q + 2LL * Q * Q;
    90     printf("%lld
    ", ans);
    91     return 0;
    92 }

    D - Half Reflector

    我们发现2*n次之后肯定就是一个循环了。前面的暴力即可。

      1 //waz
      2 #include <bits/stdc++.h>
      3  
      4 using namespace std;
      5  
      6 #define mp make_pair
      7 #define pb push_back
      8 #define fi first
      9 #define se second
     10 #define ALL(x) (x).begin(), (x).end()
     11 #define SZ(x) ((int)((x).size()))
     12  
     13 typedef pair<int, int> PII;
     14 typedef vector<int> VI;
     15 typedef long long int64;
     16 typedef unsigned int uint;
     17 typedef unsigned long long uint64;
     18  
     19 #define gi(x) ((x) = F())
     20 #define gii(x, y) (gi(x), gi(y))
     21 #define giii(x, y, z) (gii(x, y), gi(z))
     22  
     23 int F()
     24 {
     25     char ch;
     26     int x, a;
     27     while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
     28     if (ch == '-') ch = getchar(), a = -1;
     29     else a = 1;
     30     x = ch - '0';
     31     while (ch = getchar(), ch >= '0' && ch <= '9')
     32         x = (x << 1) + (x << 3) + ch - '0';
     33     return a * x;
     34 }
     35  
     36 const int N = 2e5 + 10;
     37  
     38 char str[N];
     39  
     40 int n, k;
     41  
     42 int pos(int x, int l)
     43 {
     44     int p = x + l % n;
     45     if (p > n) p -= n;
     46     return p;
     47 }
     48  
     49 int main()
     50 {
     51     gii(n, k);
     52     scanf("%s", str + 1);
     53     for (int i = 1; i <= n; ++i) str[i] -= 'A';
     54     if (k <= 2 * n + 10)
     55     {
     56         int l = 0, t = 0;
     57         for (int i = 1; i <= k; ++i)
     58         {
     59             if (!(str[pos(1, l)] ^ t))
     60             {
     61                 str[pos(1, l)] ^= 1;
     62             }
     63             else
     64             {
     65                 ++l, t ^= 1; str[pos(n, l)] = t;
     66             }
     67         }
     68         for (int i = 1; i <= n; ++i) putchar((str[pos(i, l)] ^ t) + 'A');
     69         puts("");
     70         return 0;
     71     }
     72     else
     73     {
     74         int l = 0, t = 0;
     75         for (int i = 1; i <= 2 * n + 10; ++i)
     76         {
     77             if (!(str[pos(1, l)] ^ t))
     78             {
     79                 str[pos(1, l)] ^= 1;
     80             }
     81             else
     82             {
     83                 ++l, t ^= 1; str[pos(n, l)] = t;
     84             }
     85         }
     86         k -= 2 * n + 10;
     87         if (n & 1)
     88         {
     89             str[pos(1, l)] ^= (k & 1);
     90             for (int i = 1; i <= n; ++i) putchar((str[pos(i, l)] ^ t) + 'A');
     91             puts("");
     92             return 0;
     93         }
     94         else
     95         {
     96             for (int i = 1; i <= n; ++i) putchar((str[pos(i, l)] ^ t) + 'A');
     97             puts("");
     98             return 0;
     99         }
    100     } 
    101 }

    E - Increasing Numbers

    我们发现一个上升的数肯定可以拆成很多个不同位数的111111……之和。就是(10^x-1)/9,我们暴力加一下,直接判断即可。

     1 //waz
     2 #include <bits/stdc++.h>
     3  
     4 using namespace std;
     5  
     6 #define mp make_pair
     7 #define pb push_back
     8 #define fi first
     9 #define se second
    10 #define ALL(x) (x).begin(), (x).end()
    11 #define SZ(x) ((int)((x).size()))
    12  
    13 typedef pair<int, int> PII;
    14 typedef vector<int> VI;
    15 typedef long long int64;
    16 typedef unsigned int uint;
    17 typedef unsigned long long uint64;
    18  
    19 #define gi(x) ((x) = F())
    20 #define gii(x, y) (gi(x), gi(y))
    21 #define giii(x, y, z) (gii(x, y), gi(z))
    22  
    23 int F()
    24 {
    25     char ch;
    26     int x, a;
    27     while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    28     if (ch == '-') ch = getchar(), a = -1;
    29     else a = 1;
    30     x = ch - '0';
    31     while (ch = getchar(), ch >= '0' && ch <= '9')
    32         x = (x << 1) + (x << 3) + ch - '0';
    33     return a * x;
    34 }
    35  
    36 int n;
    37  
    38 char s[500010];
    39  
    40 int x[500010];
    41  
    42 int sum;
    43  
    44 int main()
    45 {
    46     scanf("%s", s + 1);
    47     n = strlen(s + 1);
    48     reverse(s + 1, s + n + 1);
    49     for (int i = 1; i <= n; ++i) x[i] = (s[i] - 48) * 9;
    50     for (int i = 1; i <= n; ++i) x[i + 1] += x[i] / 10, x[i] %= 10;
    51     if (x[n + 1]) ++n;
    52     for (int i = 1; i <= n; ++i) sum += x[i];
    53     for (int k = 1; k <= 2 * n; ++k)
    54     {
    55         int v = 9, j = 1;
    56         while (v)
    57         {
    58             sum -= x[j];
    59             x[j] += v;
    60             v = x[j] / 10;
    61             x[j] %= 10;
    62             sum += x[j];
    63             if (j > n) ++n;
    64             ++j;
    65         }
    66         if (sum <= 9 * k) 
    67         {
    68             printf("%d
    ", k);
    69             return 0;
    70         }
    71     }
    72     return 0;
    73 }

    F - Train Service Planning

    题目都不是很懂(太菜了qwq)。。。先咕着吧。

  • 相关阅读:
    k8s-基础入门
    Compose编排Spring Cloud微服务2
    Compose 编排 SpringCloud微服务
    Docker Compose 编排微服务
    首篇博客
    Vue--计算属性和侦听器
    Vue--事件处理--事件修饰符
    css 盒子模型理解
    移动前端开发之viewport的深入理解
    js中几种实用的跨域方法原理详解
  • 原文地址:https://www.cnblogs.com/AnzheWang/p/9671734.html
Copyright © 2020-2023  润新知