• 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
  • 相关阅读:
    Git和SourceTree配合使用
    hive中数据存储格式对比:textfile,parquent,orc,thrift,avro,protubuf
    hive 实现类似 contain 包含查询
    hive函数 parse_url的使用
    Spring中注解方式的默认beanName生成规则
    @Autowired 与@Resource的区别
    js通过html的url获取参数值
    mysql模糊查询多个字段
    java获取调用当前方法的方法名和行数
    阿里druid数据源配置及数据库密码加密
  • 原文地址:https://www.cnblogs.com/Dup4/p/10090169.html
Copyright © 2020-2023  润新知