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 Eve if D=24, Christmas Eve Eve if D=23 and Christmas Eve Eve Eve if D=22.
Constraints
- 22≤D≤25
- D is an integer.
Input
Input is given from Standard Input in the following format:
D
Output
Print the specified string (case-sensitive).
Sample Input 1
25
Sample Output 1
Christmas
Sample Input 2
22
Sample Output 2
Christmas Eve Eve Eve
Be sure to print spaces between the words.
题解:
没什么好说的。
#include <cstdio> using namespace std; int main()
{
int d;
scanf("%d", &d);
if(d == )
printf("Christmas\n");
else if(d == )
printf("Christmas Eve\n");
else if(d == )
printf("Christmas Eve Eve\n");
else if(d == )
printf("Christmas Eve Eve Eve\n");
return ;
}
B Christmas Eve Eve
题目:
Time limit : 2sec / Memory limit : 1024MB
Score : 200 points
Problem Statement
In some other world, today is the day before Christmas Eve.
Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1≤i≤N) is pi yen (the currency of Japan).
He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N−1 items cost their regular prices. What is the total amount he will pay?
Constraints
- 2≤N≤10
- 100≤pi≤10000
- pi is an even number.
Input
Input is given from Standard Input in the following format:
N
p1
p2
:
pN
Output
Print the total amount Mr. Takaha will pay.
Sample Input 1
3
4980
7980
6980
Sample Output 1
15950
The 7980-yen item gets the discount and the total is 4980+7980⁄2+6980=15950 yen.
Note that outputs such as 15950.0 will be judged as Wrong Answer.
Sample Input 2
4
4320
4320
4320
4320
Sample Output 2
15120
Only one of the four items gets the discount and the total is 4320⁄2+4320+4320+4320=15120 yen.
题解:
没什么好说的。
#include <cstdio>
#include <iostream> using namespace std; int main()
{
int n;
scanf("%d", &n);
int p[], maxp = , sum = ;
for(int i = ; i < n; ++i)
{
scanf("%d", &p[i]);
maxp = max(maxp, p[i]);
sum += p[i];
}
sum = sum - maxp + maxp / ;
printf("%d\n", sum);
return ;
}
C Christmas Eve
题目:
Time limit : 2sec / Memory limit : 1024MB
Score : 300 points
Problem Statement
In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1≤i≤N) is hi meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.
More specifically, let the height of the tallest decorated tree be hmax meters, and the height of the shortest decorated tree be hmin meters. The smaller the value hmax−hmin is, the better. What is the minimum possible value of hmax−hmin?
Constraints
- 2≤K<N≤105
- 1≤hi≤109
- hi is an integer.
Input
Input is given from Standard Input in the following format:
N K
h1
h2
:
hN
Output
Print the minimum possible value of hmax−hmin.
Sample Input 1
5 3
10
15
11
14
12
Sample Output 1
2
If we decorate the first, third and fifth trees, hmax=12,hmin=10 so hmax−hmin=2. This is optimal.
Sample Input 2
5 3
5
7
5
7
7
Sample Output 2
0
If we decorate the second, fourth and fifth trees, hmax=7,hmin=7 so hmax−hmin=0. This is optimal.
There are not too many trees in these sample inputs, but note that there can be at most one hundred thousand trees (we just can't put a sample with a hundred thousand lines here).
题解:
最终的答案就是k个数中的最大高度-最小高度。要让答案尽可能的小,就要让这两个值尽可能接近。很容易想到排序一下,然后枚举第i个和第i+k-1个之间的差值(0≤i≤n-k),取最小值即可。
#include <cstdio>
#include <algorithm> using namespace std; int main()
{
int n, k;
scanf("%d %d", &n, &k);
int h[];
for(int i = ; i < n; ++i)
scanf("%d", &h[i]);
sort(h, h + n);
int ans = 1e9;
for(int i = ; i <= n - k; ++i)
ans = min(ans, h[i+k-] - h[i]);
printf("%d\n", ans);
return ;
}
D Christmas
题目:
Time limit : 2sec / Memory limit : 1024MB
Score : 400 points
Problem Statement
In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
- A level-0 burger is a patty.
- A level-L burger (L≥1) is a bun, a level-(L−1) burger, a patty, another level-(L−1) burger and another bun, stacked vertically in this order from the bottom.
For example, a level-1 burger and a level-2 burger look like BPPPB and BBPPPBPBPPPBB (rotated 90 degrees), where B and P stands for a bun and a patty.
The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
Constraints
- 1≤N≤50
- 1≤X≤( the total number of layers in a level-N burger )
- N and X are integers.
Input
Input is given from Standard Input in the following format:
N X
Output
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger.
Sample Input 1
2 7
Sample Output 1
4
There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB).
Sample Input 2
1 1
Sample Output 2
0
The bottom-most layer of a level-1 burger is a bun.
Sample Input 3
50 4321098765432109
Sample Output 3
2160549382716056
A level-50 burger is rather thick, to the extent that the number of its layers does not fit into a 32-bit integer.
题解:
题目中burger的定义是递归的定义,自然也想到用递归的方式去做。我们可以发现burger是对称的。那么就可以分段递归。nlen是每个burger的长度(高度),p记录的是每个burger含有的p的个数。这两个公式稍微推一下就可以得到,是一个等比数列的问题,这里不展开了。(事实上直接迭代也可以得到)

另外,我们可以发现X≤N的时候,ans=0;X≥nlen[N]的时候,ans=p[N]。由此可以写出代码。
注意输入输出的时候为了防止Compilation Error,用cin和cout较为妥当。
#include <cstdio>
#include <cmath>
#include <iostream> using namespace std; typedef unsigned long long ll; ll p[], nlen[]; ll solve(ll n, ll x)
{
if(x <= n) return ;
if(x >= nlen[n] - ) return p[n];
if(x == nlen[n] / + ) return (p[n] / + );
else if(x < nlen[n] / + )
return solve(n - , x - );
else
return p[n] / + + solve(n - , x - nlen[n] / - );
} int main()
{
for(int i = ; i <= ; ++i)
{
p[i] = pow(, i + ) - ;
nlen[i] = pow(, i - ) * - ;
}
ll n, x;
cin>>n>>x;
cout<<solve(n, x)<<endl;
return ;
}
AtCoder Beginner Contest 115 题解的更多相关文章
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
- AtCoder Beginner Contest 169 题解
AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
- AtCoder Beginner Contest 151 题解报告
总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...
随机推荐
- stl_heap.h
stl_heap.h // Filename: stl_heap.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http://b ...
- RTP Payload Format for Opus Speech and Audio Codec
[Docs] [txt|pdf] [Tracker] [WG] [Email] [Diff1] [Diff2] [Nits] Versions: (draft-spittka-payload-rtp- ...
- LOJ2305 「NOI2017」游戏
「NOI2017」游戏 题目背景 狂野飙车是小 L 最喜欢的游戏.与其他业余玩家不同的是,小 L 在玩游戏之余,还精于研究游戏的设计,因此他有着与众不同的游戏策略. 题目描述 小 L 计划进行$n$场 ...
- 【Python】正则表达式中使用变量
我们有时想把变量放进正则表达式中来匹配想要的结果.Python中使用 re.compile(r''+变量+''),其中正则表达式中的“变量”应为字符串形式. import re regex_test_ ...
- arm交叉编译 扫盲贴
ARM交叉编译工具链 为什么要用交叉编译器? 交叉编译通俗地讲就是在一种平台上编译出能运行在体系结构不同的另一种平台上的程序, 比如在PC平台(X86 CPU)上编译出能运行在以ARM为内核的CPU平 ...
- ES6学习之装饰器
定义:修饰器是一个对类进行处理的函数,用来修改类的行为 <注>:装饰器只能用来修改类及类的方法 类的装饰: 静态属性:只能通过类访问,修饰函数直接在类上操作 @testable class ...
- jQuery 文档操作 - html() 方法
1.转自:http://www.w3school.com.cn/jquery/manipulation_html.asp 设置所有 p 元素的内容: <html> <head> ...
- js中一些小知识点总结--持续更新
以下知识点来自于编写高质量代码-改善JavaScript程序的188个建议,只用于自我知识的补充. 一.NaN 1.NaN是一个特殊的数量值,不表示一个数字,尽管下面的代码仍然是返回类型为number ...
- 布尔类型(Boolean)
布尔类型(Boolean) 布尔类型仅包含真假,与Python不同的是其首字母小写. == 比较值相等 != 不等于 === 比较值和类型相等 !=== 不等于 || ...
- qboimathtest1 t2 配对
题目 有1~n一共n个数,n为偶数.小Q要把这n个数随机地两两配对.令每一对的权值为它们两个数的和.小Q想要知道这n/2对里最大的权值的期望是多少.请输出答案对10^9+7取模的值. [输入] 一行一 ...