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     }

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\n", res - Max / 2);
17         }
18         return 0;
19     }

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\n", res);
16         }
17         return 0;
18     }

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\n", 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\n", res);
38         }
39         return 0;
40     }

原文地址:https://www.cnblogs.com/Dup4/p/10090169.html

时间: 2024-10-30 20:24:51

AtCoder Beginner Contest 115 Solution的相关文章

AtCoder Beginner Contest 115 题解

题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit : 1024MB Score : 100 points Problem Statement In some other world, today is December D-th. Write a program that prints Christmas if D=25, Christmas E

AtCoder Beginner Contest 114 Solution

A 753 Solved. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int mp[10]; 5 6 int main() 7 { 8 mp[7] = mp[5] = mp[3] = 1; 9 int x; cin >> x; 10 puts(mp[x] ? "YES" : "NO"); 11 } B 754 Solved. 1 #include <bits/stdc++

AtCoder Beginner Contest 154 题解

人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one

AtCoder Beginner Contest 103 D(贪心)

AtCoder Beginner Contest 103 D 题目大意:n个点,除第n个点外第i与第i+1个点有一条边,给定m个a[i],b[i],求最少去掉几条边能使所有a[i],b[i]不相连. 按右端点从小到大排序,如果当前选的去掉的边在区间内,那么符合条件,否则ans++,并贪心地把去掉的边指向右端点,因为前面的区间都满足条件了,所以要去掉的边要尽量向右移使其满足更多的区间. 1 #include <iostream> 2 #include <cstdio> 3 #incl

AtCoder Beginner Contest 136

AtCoder Beginner Contest 136 Contest Duration : 2019-08-04(Sun) 20:00 ~ 2019-08-04(Sun) 21:40 Website: AtCoder BC-136 后面几题都挺考思考角度D. C - Build Stairs 题目描述: 有n座山从左到右排列,给定每一座山的高度\(Hi\),现在你可以对每座山进行如下操作至多一次:将这座山的高度降低1. 问是否有可能通过对一些山进行如上操作,使得最后从左至右,山的高度呈不下降

AtCoder Beginner Contest 155 简要题解

AtCoder Beginner Contest 155 A:签到失败,WA一次. int main() { int a, b, c; cin >> a >> b >> c; if(a == b && b == c) cout << "No"; else if(a == b || a == c || b == c) cout << "Yes"; else cout << &quo

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质)

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质) We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aiai and Vertex bibi. Consider painting each of these edges white or black. There ar

【ATcoder】AtCoder Beginner Contest 161 题解

题目链接:AtCoder Beginner Contest 161 原版题解链接:传送门 A - ABC Swap 这题太水,直接模拟即可. 1 #include <iostream> 2 using namespace std; 3 int main() { 4 int a, b, c; 5 cin >> a >> b >> c; 6 swap(a, b); 7 swap(a, c); 8 cout << a << " &

AtCoder Beginner Contest 106 ABCD

A - Garden Problem Statement There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents