CF - 794B. Cutting Carrot - 数学
2017-05-13 20:42
141 查看
1.题目描述:
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
output
input
output
Note
Definition of isosceles triangle: https://en.wikipedia.org/wiki/Isosceles_triangle.
2.题意概述:
给你一个等腰三角形,要你用n-1条垂直于高的直线将它们分成n等份,问这些直线的坐标。
3.解题思路:
既然是n等份,即每份的面积为总面积的1/n,因为三角形更好算,考虑从上往下分,前i份组成的三角形所占面积为i/n,即Si/Sn=i/n。
而由相似三角形容易得Si/Sn=Xi^2/n^2,那么再利用三角形面积公式就出来了。
PS:开始没想到那个相似三角形公式,而是推了一遍带tan的数,可能是爆精度了,样例都没过QAQ
4.AC代码:
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
3 2
output
1.154700538379 1.632993161855
input
2 100000
output
70710.678118654752
Note
Definition of isosceles triangle: https://en.wikipedia.org/wiki/Isosceles_triangle.
2.题意概述:
给你一个等腰三角形,要你用n-1条垂直于高的直线将它们分成n等份,问这些直线的坐标。
3.解题思路:
既然是n等份,即每份的面积为总面积的1/n,因为三角形更好算,考虑从上往下分,前i份组成的三角形所占面积为i/n,即Si/Sn=i/n。
而由相似三角形容易得Si/Sn=Xi^2/n^2,那么再利用三角形面积公式就出来了。
PS:开始没想到那个相似三角形公式,而是推了一遍带tan的数,可能是爆精度了,样例都没过QAQ
4.AC代码:
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define maxn 100100 #define lson root << 1 #define rson root << 1 | 1 #define lent (t[root].r - t[root].l + 1) #define lenl (t[lson].r - t[lson].l + 1) #define lenr (t[rson].r - t[rson].l + 1) #define N 1111 #define eps 1e-6 #define pi acos(-1.0) #define e exp(1.0) using namespace std; const int mod = 1e9 + 7; typedef long long ll; typedef unsigned long long ull; double n, h; double ans[1001]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock(); #endif int a,b; while (~scanf("%d%d", &a, &b)) { for (int i = 1; i < a; i++) { double temp = i; if (i == 1) printf("%.10f", b*sqrt(temp / a)); else printf(" %.10f", b*sqrt(temp / a)); } puts(""); } #ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time); #endif return 0; }
相关文章推荐
- CF 715A Plus and a square root(数学构造)
- [CF 332D]Theft of Blueprints题解中数学结论证明的翻译
- CF 658 D 数学 方程解的个数
- CF 869 B. The Eternal Immortality【数学】
- CF 476C Dreamoon and Sums[数学]
- CF - 798D. Mike and distribution - 排序+数学
- Cf 364div2 D[数学公式推导]
- CF-edu#5 E - Sum of Remainders -数学-枚举
- cf#Wunder Fund Round 2016 -A - Slime Combining-简单数学
- CF 162-div2 D 数学+dp
- CF 305B——Continued Fractions——————【数学技巧】
- cf(数学思维题)
- CF 937C. Save Energy! 二分(精度)+数学
- CF_292_B_Drazil and His Happy Friends_数学
- CF 327D - Block Tower 数学题 DFS 初看很难,想通了就感觉很简单
- CF - 805A. Fake NP - 数学
- cf 460 E. Congruence Equation 数学题
- CF 305C ——Ivan and Powers of Two——————【数学】
- CF 327C 数学题 等比公式
- (简单) CF 44D Hyperdrive,数学。