CF - 794B. Cutting Carrot - 数学

解决如何将一个等腰三角形(象征胡萝卜)通过n-1条垂直于高的直线等分为n个相同面积的部分的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ≤ 10001 ≤ 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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值