题目链接: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. nodejs stream基础知识

    分类 nodejs 的 stream 有四种: Readable:可读流 Writable: 可写流 Duplex:双工流 Transform:转换流 Readable // _read方法是从底层系 ...

  2. 关于c++中的全局变量(不赋值的全局变量算定义)

    定义有三种: 1.不赋值的定义:int a; 2.赋值的定义:int a=5; 或者 int a;a=5; 3.加extern的定义:extern int a=5;//其实和不加是一样的. 声明只有一 ...

  3. printf 小代码 大问题

    技术 对于我来说 是我前进的动力 虽然有时候感觉会枯燥乏味 不过没关系 放松一下紧张的心态 做一些你能够是你进步的事情  这样 你才会觉得  每天都过得很充实  学海无涯  坚持追求你所想要实现的梦想 ...

  4. ngget配置

    Install-Package NuGet.CommandLine nuget spec nuget pack Jryg.VirtualNumber.ClientNet4.csproj -Includ ...

  5. bzoj 4540: [Hnoi2016]序列 莫队

    题目: 给定长度为n的序列:a1,a2,-,an,记为a[1:n].类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,-,ar- 1,ar.若1≤l≤s≤t≤r≤n,则称a[s:t]是a ...

  6. sessionStorage,localStorage,cookies

    1 HTML5的Storage主要分为两种:localStorage与sessionStorage,这两者主要在生命周期上有较明显的差别,localStorage的生命周期较长,原则上要等到透过Jav ...

  7. 洛谷【P1177】【模板】归并排序

    题目传送门:https://www.luogu.org/problemnew/show/P1177 归并排序: 1.先将\(a\)数组的区间\([l,mid],[mid+1,r]\)排成有序的. 2. ...

  8. MongoDB3.2.8创建初始用户

    启动MongoDB前需要关闭配置文件中的auth选项,否则不能创建用户 首先创建用户管理用户 use admin db.createUser({user:'admin',pwd:'123456', r ...

  9. .net wcf调用java的需要认证的接口

    1.wcf直接添加java的webservice地址,这都是常规操作,没必要好说 2.修改config配置文件,添加headers消息头节点,这个需要注意 3.OK直接调用里面的方法即可,全部搞定 & ...

  10. 设置win7资源管理器启动时的默认位置-windows-操作系统-网页教学网

    设置win7资源管理器启动时的默认位置-windows-操作系统-网页教学网 如何设置win7资源管理器启动时的默认位置?我不太习惯 Win 7 的资源管理器默认总是打开库,我还是喜欢资源管理器打开树 ...