B. Cutting Carrot
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces of equal area.
Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to h. Igor wants to make n - 1 cuts parallel to the base to cut the carrot into n pieces. He wants to make sure that all n pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area?
Illustration to the first example.
Input
The first and only line of input contains two space-separated integers, n and h (2 ≤ n ≤ 1000, 1 ≤ h ≤ 105).
Output
The output should contain n - 1 real numbers x1, x2, ..., xn - 1. The number xi denotes that the i-th cut must be made xi units away from the apex of the carrot. In addition, 0 < x1 < x2 < ... < xn - 1 < h must hold.
Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10 - 6.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .
Examples
input
Copy
3 2
output
1.154700538379 1.632993161855
input
Copy
2 100000
output
70710.678118654752
Note
Definition of isosceles triangle: https://en.wikipedia.org/wiki/Isosceles_triangle.
【题意】有一个等腰三角形,高度为h,底边长为1,把这个三角形按照面积平均分成n块,每块的面积都相等,求每一块底边距离三角形顶部的距离。
【思路】相似三角形对应边比的平方等于面积之比。
【代码如下】
#include <bits/stdc++.h>
using namespace std;
vector<double>vct;
int n,h;
int main(){
scanf("%d%d",&n,&h);
double area = h*1.0/n;
for(int i = 1; i < n; i ++){
double d_area = i*area;
double t = (sqrt(d_area/h)) * h;
if(i>1) printf(" ");
printf("%.7lf",t);
}
printf("\n");
return 0;
}