题目链接: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≤iN) 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≤iN) 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 hmaxhmin is, the better. What is the minimum possible value of hmaxhmin?

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 hmaxhmin.

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 hmaxhmin=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 hmaxhmin=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 题解的更多相关文章

  1. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  2. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  3. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  4. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  5. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  6. AtCoder Beginner Contest 172 题解

    AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...

  7. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

  8. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  9. AtCoder Beginner Contest 151 题解报告

    总的来说,这次的题目比较水,然而菜菜的我并没有把所有题目都做完,话不多说,直接来干货: A:Next Alphabet 题目链接:https://atcoder.jp/contests/abc151/ ...

随机推荐

  1. python-Django监控系统二次开发Nagios

    1.Nagios安装 yum install -y nagios.i686 yum install -y nagios-plugins-all.i686 安装完后会在apache的配置文件目录下/et ...

  2. 51nod 1829(函数)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1829 本题目相当于: n个不同的小球,放入到m个可区分的盒子 ...

  3. bzoj4010

    知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高到低给予1到N的顺序编号,预估质量最高的菜肴编号为1. 由于菜肴之间口味搭 ...

  4. NOIp2018集训test-10-18 (bike day4)

    这是一套简单题,这几天的考试让bike老爷感觉很绝望,说实话我也确实不知道还能怎么更简单了. 这几天的题换做llj.sxy应该都能轻松AK吧,至少随便考个250+应该不是问题吧,我越来越觉得觉得我跟他 ...

  5. arguments对象的实例使用

    新年第一记,从这里开始,先来个简单的!去年的知识梳理留下了很多尾巴,原因有很多(知识储量不足,懒了,项目多...) lg:都是借口~   好吧,我承认,这都是借口,今年一定把尾巴清干净! 下面要写的是 ...

  6. Azure Public IP DNS域名

    在某些环境下,PIP是Azure上的一种比较好的解决方案处理一些特殊的环境.比如大量的端口需要打开.向外部的访问非常多等等. 但目前,Azure的Reserved IP address不用应用到PIP ...

  7. vijos1782:借教室

    描述 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海量租借教室的信息,我们自然希望 ...

  8. Trie(前缀树/字典树)及其应用

    Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...

  9. Java访问子类对象的实例变量

    对于Java这种语言来说,一般来说,子类可以调用父类中的非private变量,但在一些特殊情况下, Java语言可以通过父类调用子类的变量 具体的还是请按下面的例子吧! package com.yon ...

  10. oracle--pl/sql变量定义----

    一.变量介绍 在编写pl/sql程序时,可以定义变量和常量:在pl/sql程序中包括有: 1).标量类型(scalar) 2).复合类型(composite) --用于操作单条记录 3).参照类型(r ...