A15835 | Another n-dimensional chocolate bar
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mom bought the boy Vasya a $n$ -dimensional chocolate bar, which is a $n$ -dimensional cube with the length of each side equal to $1$ . The chocolate is planned to be divided into slices. According to the $i$ th dimension, it can be divided by hyperplanes into $a_i$ equal parts. Thus, the chocolate is divided in total into $a_1 \cdot a_2 \cdot a_3 \cdot \ldots \cdot a_n$ slices, each slice has a length of $i$ -th dimension equal to $\frac{1}{a_i}$ , respectively, the volume of each slice is $\frac{1}{a_1 a_2 \cdots a_n}$ .Vasya and his friends want to cut a chocolate bar to get at least $k$ pieces, while Vasya wants to maximize the volume of the smallest of them. It is possible to cut the chocolate bar only at the junction of the lobules, and each incision must pass through the entire chocolate bar along some hyperplane involved in the formation of lobules. Only after making all the cuts, Vasya disassembles the chocolate into pieces.
More formally, Vasya wants to choose the numbers $b_1, b_2, \dots, b_n$ ( $1 \le b_i \le a_i$ ) — the number of parts into which Vasya will cut the chocolate bar along each dimension. The condition $b_1 \cdot b_2 \cdot \ldots \cdot b_n \ge k$ must be met to get at least $k$ pieces after all cuts. It can be noted that with optimal cutting with such parameters, the minimum piece will contain $\lfloor \frac{a_1}{b_1} \rfloor \dotsm \lfloor \frac{a_n}{b_n} \rfloor$ slices, and its volume will be equal to $\lfloor \frac{a_1}{b_1} \rfloor \dotsm \lfloor \frac{a_n}{b_n} \rfloor \cdot \frac{1}{a_1 a_2 \cdots a_n}$ .
Vasya wants to get the maximum possible value of the volume of the minimum piece multiplied by $k$ , that is, he wants to maximize the number of $\lfloor \frac{a_1}{b_1} \rfloor \dotsm \lfloor \frac{a_n}{b_n} \rfloor \cdot \frac{1}{a_1 a_2 \cdots a_n} \cdot k$ . Help him with this.
More formally, Vasya wants to choose the numbers $b_1, b_2, \dots, b_n$ ( $1 \le b_i \le a_i$ ) — the number of parts into which Vasya will cut the chocolate bar along each dimension. The condition $b_1 \cdot b_2 \cdot \ldots \cdot b_n \ge k$ must be met to get at least $k$ pieces after all cuts. It can be noted that with optimal cutting with such parameters, the minimum piece will contain $\lfloor \frac{a_1}{b_1} \rfloor \dotsm \lfloor \frac{a_n}{b_n} \rfloor$ slices, and its volume will be equal to $\lfloor \frac{a_1}{b_1} \rfloor \dotsm \lfloor \frac{a_n}{b_n} \rfloor \cdot \frac{1}{a_1 a_2 \cdots a_n}$ .
Vasya wants to get the maximum possible value of the volume of the minimum piece multiplied by $k$ , that is, he wants to maximize the number of $\lfloor \frac{a_1}{b_1} \rfloor \dotsm \lfloor \frac{a_n}{b_n} \rfloor \cdot \frac{1}{a_1 a_2 \cdots a_n} \cdot k$ . Help him with this.
输入格式
The first line contains two integers $n$ and $k$ $(1 \le n \le 100$ , $1 \le k \le 10^7)$ — the dimension of the chocolate bar, and how many parts it needs to be divided into.
The second line contains $n$ integers $a_1,\ a_2,\ \dots,\ a_n$ $(1 \le a_i \le 10^7)$ — the number of pieces on which the chocolate is placed along each of the dimensions.
The second line contains $n$ integers $a_1,\ a_2,\ \dots,\ a_n$ $(1 \le a_i \le 10^7)$ — the number of pieces on which the chocolate is placed along each of the dimensions.
输出格式
Print one number — the maximum possible volume of the smallest of the obtained pieces, multiplied by $k$ , with an absolute or relative error of no more than $10^{-9}$ .
If it is impossible to cut a chocolate bar into at least $k$ pieces under the given restrictions, output $0$ .
If it is impossible to cut a chocolate bar into at least $k$ pieces under the given restrictions, output $0$ .
输入输出样例
输入 #1
1 2 5
输出 #1
0.8
输入 #2
2 6 5 10
输出 #2
0.72
输入 #3
2 7 4 4
输出 #3
0.875
输入 #4
2 3 4 5
输出 #4
0.75
输入 #5
4 444 57 179 239 2
输出 #5
0.97557326850704739751
输入 #6
2 5 2 2
输出 #6
0
In the first example, a one – dimensional chocolate bar can be divided as follows:

Then the answer will be $\frac{2}{5} \cdot 2 = 0.8$
In the second example, the chocolate bar can be cut as follows:

Then the answer will be $\frac{2}{5} \cdot \frac{3}{10} \cdot 6 = 0.72$
In the third example, the chocolate bar can be cut as follows:
 Then the answer will be $\frac{2}{4} \cdot \frac{1}{4} \cdot 7 = 0.875$

Then the answer will be $\frac{2}{5} \cdot 2 = 0.8$
In the second example, the chocolate bar can be cut as follows:

Then the answer will be $\frac{2}{5} \cdot \frac{3}{10} \cdot 6 = 0.72$
In the third example, the chocolate bar can be cut as follows:
 Then the answer will be $\frac{2}{4} \cdot \frac{1}{4} \cdot 7 = 0.875$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted