LightOJ 1297 - Largest Box (二分查找)
来源:互联网 发布:本机端口号查询 编辑:程序博客网 时间:2024/05/29 06:35
1297 - Largest Box
Time Limit: 2 second(s)
Memory Limit: 32 MB
In the following figure you can see a rectangular card. The width of the card isW 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 ofx.
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 than10-6 will be ignored.
Sample Input
Output for Sample Input
3
2 10
3.590 2.719
8.1991 7.189
Case 1: 4.513804324
Case 2: 2.2268848896
Case 3: 33.412886
题意:给出一纸片,长为L,宽为W,如图将其减去4个边长为x的正方形,在按虚线上折,成为一个没有盖子的长方体容器。x的大小是不确定的,问容器最大容积是多少
先得到长方体的体积式,再二分查找最大体积,代码如下:
#include<cstdio>#include<cmath>double l,w;double g(double x){return 12*x*x-4*(w+l)*x+w*l;}double f(double x){return 4*x*x*x-2*(w+l)*x*x+w*l*x;}int main(){int t,k=1;double z,left,right,mid;scanf("%d",&t);while(t--){scanf("%lf%lf",&l,&w);if(l>w)z=w;else z=l;left=0;right=z/2;while(right-left>1e-8){mid=(left+right)/2;if(g(mid)<0)right=mid;elseleft=mid;}printf("Case %d: %.6lf\n",k++,f(mid));}return 0;}
- LightOJ 1297 - Largest Box (二分查找)
- LightOJ 1297 - Largest Box【二分】
- lightoj 1297 - Largest Box 三分查找
- Lightoj 1297 - Largest Box
- lightoj 1297 - Largest Box
- lightoj 1297 Largest Box
- LightOJ 1297: Largest Box【数学】
- lightOJ 1297 - Largest Box 【数学题】
- lightoj 1297 - Largest Box 【函数最值】
- LightOJ 1297 Largest Box【简单计算几何】
- LightOJ 1297 - Largest Box (一元三次方程求最大值)
- lightoj--1294--Largest Box(三分)
- Light OJ 1297 - Largest Box 【求导或二分】
- LightOJ _1138(二分查找)
- 【Light】[1297]Largest Box
- light oj 1297 Largest Box
- light oj 1297 Largest Box
- 二分--LIGHTOJ 1088查找区间(水题)
- 安卓常用权限
- 【线性代数公开课MIT Linear Algebra】 第十七课 正交基和正交矩阵
- Http和Https简介
- poj 3461 Oulipo
- Struts2和Spring的mvc的区别
- LightOJ 1297 - Largest Box (二分查找)
- hdu5510 kmp+二分
- [004]微信公众账号开发教程第1篇-根据用户openID获取用户基本信息
- PHP与JavaScript在处理数组方面的不同之处
- [Unity热更新]lua基础(一)
- poj 2752 Seek the Name, Seek the Fame
- 如何解决ArcGIS Runtime SDK for Android中文标注无法显示的问题
- ArcGIS for Server内置JS Viewer的离线部署和配置
- ArcGIS for Server 10.3.X 新型紧凑型缓存的解读和应用