题目链接: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. SpringBoot_异常_01_Caused by: java.lang.BootstrapMethodError: java.lang.NoSuchMethodError

    一.异常信息 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gsonB ...

  2. JSP分页1

    分页 1.什么分页? 第N页/共M页 首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页 口 go 分页的优点:只查询一页,不用查询所有页! 2.分页数据 页面的数据都是由Servl ...

  3. hibernate复习第(4)天

    1.hibernate的映射类型.hbm.xml中property中的type属性.这个type属性是表示持久化类中的属性对应数据库中的什么数据类型,用来构建一种映射type的可选值:hibernat ...

  4. L101

    It isn't where you came from. It's where you're going that counts.起点并不重要,重要的是,你要去往何方.Nothing is impo ...

  5. tomcat报错:Wrapper cannot find servlet class ...

    tomcat发布工程时,在浏览器输入正确的地址,遇到如下问题: HTTP Status 500 - javax.servlet.ServletException: Wrapper cannot fin ...

  6. 搭建 Http Dynamic Streaming 点播/直播服务器

    1.        HTTP Origin Module的处理数据流: a)         客户端发送媒体索引请求到Apache.例如: http://www.example.com/media/  ...

  7. rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加

    关键词:Nignx(http服务器):rtmp,hls(流媒体服务) 前言:感谢开源,感谢战斗民族.现在在做流媒体服务的一些工作,流媒体服务器搭建的网上教程多入牛毛,但是细细查看,发现很多同志贴上来的 ...

  8. ONVIF测试方法及工具

    设备是否支持ONVIF验证1 ONVIF Test Tool安装1.1PC安装环境要求:装有Microsoft .Net Framework 3.5或以上版本.1.2安装源文件请见:ONVIF Con ...

  9. 股神小D

    题目大意: 给定一棵树,每一条边有$L,R$两种权值,求有多少条路径满足$\max(L)\leq\min(R)$. 解法$1-$点分治$+$二维数点 统计树上的路径应首先想到点分治,我们很显然可以搜出 ...

  10. noip前打板子 qwq

    在某咕上打了一晚上的模板 感觉还好... #include<bits/stdc++.h> #define LL long long using namespace std; inline ...