zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 115 Solution

    A Christmas Eve Eve Eve

    Solved.

     1     #include <bits/stdc++.h>
     2     using namespace std;
     3      
     4     int main()
     5     {
     6         int n;
     7      
     8         while (scanf("%d", &n) != EOF)
     9         {
    10             printf("Christmas"); 
    11             int need = 3 - (n - 22);
    12             for (int i = need; i; --i) printf(" Eve");
    13             puts("");
    14         }
    15         return 0;
    16     }
    View Code

    B Christmas Eve Eve

    Solved.

     1     #include <bits/stdc++.h>
     2     using namespace std;
     3      
     4     int main()
     5     {
     6         int n;
     7         while (scanf("%d", &n) != EOF)
     8         {
     9             int res = 0, Max = 0;
    10             for (int i = 1, p; i <= n; ++i)
    11             {
    12                 scanf("%d", &p);
    13                 res += p;
    14                 Max = max(Max, p);
    15             }
    16             printf("%d
    ", res - Max / 2);
    17         }
    18         return 0;
    19     }
    View Code

    C Christmas Eve

    Solved.

     1     #include <bits/stdc++.h>
     2     using namespace std;
     3      
     4     #define N 100010
     5     int n, k, h[N];
     6      
     7     int main()
     8     {
     9         while (scanf("%d%d", &n, &k) != EOF)
    10         {
    11             for (int i = 1; i<= n; ++i) scanf("%d", h + i);
    12             sort(h + 1, h + 1 + n, [](int a, int b) { return a > b; });
    13             int res = 1e9;
    14             for (int i = 1; i + k - 1 <= n; ++i) res = min(res, h[i] - h[i + k - 1]);
    15             printf("%d
    ", res);
    16         }
    17         return 0;
    18     }
    View Code

    D Christmas

    Solved.

    题意:

    递归定义了一个汉堡,显然它是对称的,求从一端吃掉它长度L,吃掉多少patty

    思路:

    显然,汉堡的长度和拥有patty的个数都是可以线性递推的,先预处理

    然后按区间递归下去求答案即可。

     1     #include <bits/stdc++.h>
     2     using namespace std;
     3      
     4     #define ll long long
     5     #define N 110
     6     int n; ll x; 
     7     ll len[N], tot[N]; 
     8     ll res;
     9      
    10     void DFS(ll l, ll r, int cur)
    11     {
    12         //printf("%lld %lld %d
    ", l, r, cur);
    13         if (cur < 0 || l > x) return;  
    14         if (r <= x) 
    15         {
    16             res += tot[cur]; 
    17             return;
    18         }
    19         ll mid = (l + r) >> 1;
    20         if (mid <= x) ++res;
    21         DFS(l + 1, mid - 1, cur - 1);
    22         DFS(mid + 1, r - 1, cur - 1);
    23     }
    24      
    25     int main()
    26     {
    27         len[0] = 1;
    28         for (int i = 1; i <= 50; ++i)
    29             len[i] = 2 * len[i - 1] + 3;
    30         tot[0] = 1;
    31         for (int i = 1; i <= 50; ++i)
    32             tot[i] = 2 * tot[i - 1] + 1;
    33         while (scanf("%d%lld", &n, &x) != EOF)
    34         {
    35             res = 0;
    36             DFS(1, len[n], n); 
    37             printf("%lld
    ", res); 
    38         }
    39         return 0;
    40     }
    View Code
  • 相关阅读:
    命令别名
    文件的元数据
    bash命令练习
    bash的使用
    Linux系统下的文件管理类常命令及使用方式
    Linux获取命令帮助、man文档章节的划分
    Linux目录名、命名规则及功能规定
    Linux命令使用格式
    springmvc 异常处理
    oracle 笔记一
  • 原文地址:https://www.cnblogs.com/Dup4/p/10090169.html
Copyright © 2011-2022 走看看