AtCoder Beginner Contest 115 Solution
Posted dup4
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AtCoder Beginner Contest 115 Solution相关的知识,希望对你有一定的参考价值。
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 }
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 }
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 }
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 }
以上是关于AtCoder Beginner Contest 115 Solution的主要内容,如果未能解决你的问题,请参考以下文章
AtCoder Beginner Contest 115 题解