AtCoder Beginner Contest 115 Solution

时间:2023-01-05 03:19:36

A Christmas Eve Eve Eve

Solved.

     #include <bits/stdc++.h>
using namespace std; int main()
{
int n; while (scanf("%d", &n) != EOF)
{
printf("Christmas");
int need = - (n - );
for (int i = need; i; --i) printf(" Eve");
puts("");
}
return ;
}

B Christmas Eve Eve

Solved.

     #include <bits/stdc++.h>
using namespace std; int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
int res = , Max = ;
for (int i = , p; i <= n; ++i)
{
scanf("%d", &p);
res += p;
Max = max(Max, p);
}
printf("%d\n", res - Max / );
}
return ;
}

C Christmas Eve

Solved.

     #include <bits/stdc++.h>
using namespace std; #define N 100010
int n, k, h[N]; int main()
{
while (scanf("%d%d", &n, &k) != EOF)
{
for (int i = ; i<= n; ++i) scanf("%d", h + i);
sort(h + , h + + n, [](int a, int b) { return a > b; });
int res = 1e9;
for (int i = ; i + k - <= n; ++i) res = min(res, h[i] - h[i + k - ]);
printf("%d\n", res);
}
return ;
}

D Christmas

Solved.

题意:

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

思路:

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

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

     #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 110
int n; ll x;
ll len[N], tot[N];
ll res; void DFS(ll l, ll r, int cur)
{
//printf("%lld %lld %d\n", l, r, cur);
if (cur < || l > x) return;
if (r <= x)
{
res += tot[cur];
return;
}
ll mid = (l + r) >> ;
if (mid <= x) ++res;
DFS(l + , mid - , cur - );
DFS(mid + , r - , cur - );
} int main()
{
len[] = ;
for (int i = ; i <= ; ++i)
len[i] = * len[i - ] + ;
tot[] = ;
for (int i = ; i <= ; ++i)
tot[i] = * tot[i - ] + ;
while (scanf("%d%lld", &n, &x) != EOF)
{
res = ;
DFS(, len[n], n);
printf("%lld\n", res);
}
return ;
}