小白题解 Codeforces 794B Cutting Carrot
来源:互联网 发布:js dom编程艺术 pdf 编辑:程序博客网 时间:2024/05/29 04:51
(水题)题目链接:点击打开链接
题目大意:给定一个三角形,底始终为1,高h,用平行于底边的线将它分成面积相等的n份,分别求第i份的底边到大三角形定点的距离。
分析:设第i份对应高为Y,由每份面积相等可以写出递推式:Yi^2 * k-Y(i-1)^2 * k=Y1^2 * k,进一步可以求出通项公式为Yi=pow(i*h^2/n , 0.5)。好啦,下面就是AC代码了。
#include<cstdio>#include<cmath>using namespace std;double f[1000+5];int main(){ int n; double h; scanf("%d%lf",&n,&h); double base=h*h/n; //这部分先计算出来,可以避免重复计算 for(int i=1;i<n;i++) { f[i]=sqrt(i*base); } for(int i=1;i<n;i++) printf("%.12f%c",f[i],i==n-1?'\n':' '); //输出形式与样例保持一致 return 0;}
2 0
- 小白题解 Codeforces 794B Cutting Carrot
- codeforce B. Cutting Carrot
- Codeforces Round #414 B. Cutting Carrot 几何二分
- Codeforces Round #414, rated, Div. 1 + Div. 2 B. Cutting Carrot+【等腰三角形等比例缩小】
- Codeforces 799A Carrot Cakes 题解
- 小白题解 Codeforces 805B 3-palindrome
- 小白题解 Codeforces 807B T-Shirt Hunt
- 小白题解 Codeforces 798B Mike and strings
- 小白题解 Codeforces 785B Anton and Classes
- [博弈 杂题] Codeforces 794E Round #414 E. Choosing Carrot
- 小白题解 Codeforces 794A Bank Robbery
- 小白题解 Codeforces 785A
- 趣题 CodeForces 111B题解
- Codeforces B. Taxi 算法题解
- codeforces-158B-Taxi题解
- Codeforces 707B Bakery 题解
- Codeforces 298B Sail 题解
- Codeforces #521B: Cubes 题解
- C语言补充学习
- web.js.this详解
- 1017. A除以B (20)
- System Verilog视频学习笔记(9)- Inheritance
- jQuery的属性与样式
- 小白题解 Codeforces 794B Cutting Carrot
- 数塔问题
- ubuntu mongoDB的一些相关基本操作
- 1018. 锤子剪刀布 (20)
- 判断一个整数转换成二进制后1的个数
- [安卓基础]学习第五天
- 1019. 数字黑洞 (20)
- 1020. 月饼 (25)
- python