Codeforces Round #414 B. Cutting Carrot 几何二分
来源:互联网 发布:淘宝店铺导航全屏代码 编辑:程序博客网 时间:2024/05/22 08:05
题目链接: Cutting Carrot
题目大意
一个等腰三角形, 底边长为1, 高为H, 要等分成n分, 求怎么切
思路
可以推出公式来, 懒得推, 直接二分好了, 浮点数的二分好好写
代码
#include <bits/stdc++.h>using namespace std;const int MAXN = 1100;const double eps = 1e-10;double cal(double H, double h, double L)//计算高为H, 底边长为L的等腰三角形下面高为h的等要梯形面积, H==h就是求三角形面积{ double l = L-(h*L)/H; return (L+l)*h/2.0;}double bs(double s, double H, double L){ double low = 0, high = H, mid; while(high-low >= eps) { mid = (low+high)/2; if(cal(H, mid, L) < s) low = mid; else high = mid; } return low;}int main(){ int n; double H; cin >> n >> H; double S = cal(H, H, 1); double s = S/n; double h[MAXN]; h[0] = H; for(int i=1; i<n; ++i) { h[i] = h[i-1] - bs(s, h[i-1], h[i-1]/H); } for(int i=n-1; i>0; --i) printf("%.12f ", h[i]); return 0;}
阅读全文
0 0
- Codeforces Round #414 B. Cutting Carrot 几何二分
- Codeforces Round #414, rated, Div. 1 + Div. 2 B. Cutting Carrot+【等腰三角形等比例缩小】
- codeforce B. Cutting Carrot
- 小白题解 Codeforces 794B Cutting Carrot
- [博弈 杂题] Codeforces 794E Round #414 E. Choosing Carrot
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces Round #403 B 二分,C , 染色
- Codeforces Round #413 Div. 1 + Div. 2 A. Carrot Cakes
- codeforces Round #413 Div. 1 + Div. 2 A Carrot Cakes
- codeforces Round #413 Div. 1 + Div. 2 A Carrot Cakes
- 【计算几何】Codeforces Round #113 (Div. 2)-B. Polygons
- Codeforces Round #287 (Div. 2)B(几何)
- Codeforces Round #176 (Div. 2) B. Pipeline//二分查找
- Codeforces Round #271 (Div. 2) --B Worms (二分)
- Codeforces Round #275(Div2) B.Friends and Presents 二分+数学
- Codeforces Round #276 (Div. 2) B. Valuable Resources 二分
- Codeforces Round #311 (Div. 2) B. Pasha and Tea【二分】
- Codeforces Round #334 B. More Cowbell (二分 + 贪心)
- tomcat部署web项目
- POJ 1556 The Doors(线段交+最短路)
- 关于一些TCP IP协议的解释ps:来自于网络的收集
- HTML5表单设置
- 线程调度
- Codeforces Round #414 B. Cutting Carrot 几何二分
- 记一次微信朋友圈逆向
- javascript--通过循环生成A、B、C、D
- 6/28
- aa
- 寻找好的估计量
- codeforces 820A Mister B and Book Reading
- 200. Number of Islands
- shell脚本编程实例--进度条,求和&平均值,斐波那契,改变字符串大小顺序