HDU 5984 Pocky 【思维 数学】
来源:互联网 发布:js数组取前几个 编辑:程序博客网 时间:2024/06/05 07:27
Pocky
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 756 Accepted Submission(s): 424
Problem Description
Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative stripes in the coating, of length L.
While the length of remaining pocky is longer than d, we perform the following procedure. We break the pocky at any point on it in an equal possibility and this will divide the remaining pocky into two parts. Take the left part and eat it. When it is not longer than d, we do not repeat this procedure.
Now we want to know the expected number of times we should repeat the procedure above. Round it to 6 decimal places behind the decimal point.
While the length of remaining pocky is longer than d, we perform the following procedure. We break the pocky at any point on it in an equal possibility and this will divide the remaining pocky into two parts. Take the left part and eat it. When it is not longer than d, we do not repeat this procedure.
Now we want to know the expected number of times we should repeat the procedure above. Round it to 6 decimal places behind the decimal point.
Input
The first line of input contains an integer N which is the number of test cases. Each of the N lines contains two float-numbers L and d respectively with at most 5 decimal places behind the decimal point where 1 ≤ d, L ≤ 150.
Output
For each test case, output the expected number of times rounded to 6 decimal places behind the decimal point in a line.
Sample Input
61.0 1.02.0 1.04.0 1.08.0 1.016.0 1.07.00 3.00
Sample Output
0.0000001.6931472.3862943.0794423.7725891.847298
题意为给你一个长为L的蛋糕 一刀一刀随机切 切一刀后分为两部分 丢一部分 当剩下的那部分不长于d时停止 问这个过程预期要切几刀。
根据题意可以知道 在最开始分为两种情况 切或者不切 当d的值大于或者等于L时 不需要进行上述步骤 直接输出0即可 当没出现0的情况时 最少的预期也是要切1刀 所以我们将1提出来
既然是随机下刀 那么就不能用传统方式计算期望 我们来分析样例 分别在提出1后 是0.69,1.38,2.07,2.77
因为ln2的值是0.69 而且我们又发现后面几个数分别是2*ln2 3*ln2 4*ln2
ln2+ln2=ln2*2=ln4 ln4+ln2=ln8
在看样例输入 2 4 8 16 符合上述ln2的规律
所以我刚开始大胆的直接输出1+ln(l) 但是在最后一个样例出现差错
按照上述规律 输出2.94 比正确输出高出1点多 所以我们要想办法减少输出的数并且同时不能影响之前的数据
分析ln()函数 需要减少括号内的值 而且之前的数据是带1的 d为1 那么正好l/d是不影响之前的输出值的 而且还能减少7 3 样例的输出 所以尝试输出1+ln(l/d) 成功
代码如下
#include<bits/stdc++.h>using namespace std;int main(){ int t; scanf("%d",&t); while(t--) { double l,d; scanf("%lf%lf",&l,&d); if(d>=l) printf("0.000000\n"); else { printf("%.6lf\n",1+log(l/d)); } } return 0;}
阅读全文
0 0
- HDU 5984 Pocky 【思维 数学】
- 【HDU 5984 Pocky】+ 数学
- HDU 5984 Pocky (数学)
- HDU 5984 Pocky
- HDU-5984-Pocky
- HDU 5984 Pocky
- HDU 5984Pocky
- Pocky HDU
- 【HDU5984】Pocky(数学)
- hdu 5984 Pocky (16青岛现场赛)找规律
- hdu 4950 Monster (数学思维)
- hdu5984 Pocky(猜数学期望公式)
- 杭电5984之Pocky
- hdu 4104 Discount (思维 数学归纳法)
- hdu 4710 Balls Rearrangement (数学思维)
- hdu 4091 数学思维题贪心
- 【HDU】-1214-圆桌会议(数学,思维)
- hdu 6048 逆序数+思维数学
- JavaWeb项目上传到服务器的步骤
- C++基础知识点总结
- Spring Bean初探
- 五分钟彻底理解ReentrantReadWriteLock
- (作业)Swift闭包、扩展、泛型
- HDU 5984 Pocky 【思维 数学】
- C语言学习摘要
- Android 最常用的设计模式八 安卓源码分析—工厂方法模式factory
- asp.net.core教程
- 区块链技术指南
- 给定一个无序数组,包含正数、负数和0,要求从中找出3个数的乘积,使得乘积最大
- node.js基础
- 吾八哥学Python(二):Python代码编辑器的选用
- preserve-3d