LightOJ 1297
来源:互联网 发布:python图像识别库 编辑:程序博客网 时间:2024/06/04 18:14
Description
In the following figure you can see a rectangular card. The width of the card is W and length of the card is L and thickness is zero. Four (x*x) squares are cut from the four corners of the card shown by the black dotted lines. Then the card is folded along the magenta lines to make a box without a cover.
Given the width and height of the box, you will have to find the maximum volume of the box you can make for any value of x.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case starts with a line containing two real numbers L and W (0 < L, W < 100).
Output
For each case, print the case number and the maximum volume of the box that can be made. Errors less than 10-6 will be ignored.
Sample Input
3
2 10
3.590 2.719
8.1991 7.189
Sample Output
Case 1: 4.513804324
Case 2: 2.2268848896
Case 3: 33.412886
题意:在矩形的四个角割掉四个边长为X的小正方形,求出剩下的部分折成的无顶长方体or(正方体)的体积最大为???
思路:V=x*(w-2*x)*(l-2x) ,然后对其进行求导得到变化趋势,再用二分求得最大值!
代码:
#include<stdio.h>#include<string.h>double w,l;double min(double x,double y){if(x>y)return y;return x;}double js(double x){return x*(w-2*x)*(l-2*x);//体积的计算! }double jsd(double x){return (w-2*x)*(l-2*x)-2*x*(l-2*x)-2*x*(w-2*x);//倒数! }int main(){int t,mark=1;scanf("%d",&t);while(t--){scanf("%lf%lf",&w,&l);double left=0.0,right=min(w,l),mid;while(right-left>=0.00000001)//二分 { mid=(left+right)/2;double count=jsd(mid);if(count>0)//在递增的区间倒数大于零! left=mid;elseright=mid;}printf("Case %d: %.6lf\n",mark++,js(mid));}return 0;}
- LightOJ 1297
- lightoj 1297
- Lightoj 1297 - Largest Box
- lightoj 1297 - Largest Box
- lightoj 1297 Largest Box
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- [LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- 如何扩展 Visual Studio 编辑器
- (2)二叉树构造算法的验证
- 第十周 二叉树算法库
- c:for 标签的问题javax.servlet.jsp.jstl.core.LoopTagStatus
- Reader And Writer
- LightOJ 1297
- 谁动了我的服务器!
- 使用AFNetworking进行图片上传
- Block定义与使用
- oracle数据库的导出与导入备忘
- 公式推导
- 顺序环形队列
- 第十一周 项目一 验证算法
- Chipmunk僵尸物理对象的出现和解决(六)