Light OJ 1297 - Largest Box 【求导或二分】
2015-11-08 20:07
447 查看
1297 - Largest Box
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 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).
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.
恩,可以直接求导得,也可以二分。。。(这里是二分)
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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.
|
|
3 2 10 3.590 2.719 8.1991 7.189 | Case 1: 4.513804324 Case 2: 2.2268848896 Case 3: 33.412886 |
#include <iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; double l,w; double f(double x) { return 12*x*x-4*w*x-4*l*x+l*w; } double bsearch(double l,double r) { double mid; while(r-l>=10e-10) { mid=(l+r)/2; if(f(mid)>0) l=mid; else r=mid; } return mid; } int main() { int t,cnt=0; double x,v,m; scanf("%d",&t); while(t--) { scanf("%lf%lf",&l,&w); m=l<w?l:w; m=m/2; x=bsearch(0,m); v=x*(l-2*x)*(w-2*x); printf("Case %d: %.10lf\n",++cnt,v); } return 0; }
相关文章推荐
- UML之宏观概述
- 一封来自网络的情书
- 线程间通信之Handler
- C语言学习字符串和指针
- 错综忙乱的大千世界
- HDU 4574Bombs
- leetcode刷题,总结,记录,备忘300
- 安装maven
- eclipse 自定义注释模板
- MySQL学习笔记(5)之数据定义类型
- 给电影表和模型添加新字段
- android 页面转换所遇的问题——you nedd use a Theme.AppCompat theme
- Android控件之自定义EditText
- Light OJ 1294 - Positive Negative Sign 【规律 水题】
- 信息安全系统设计基础第九周学习总结
- 学习lofter 让图片适应各个分辨率的方法
- Android分享功能
- 数据库管理
- IOS UISwitch 感觉官方提供的拓展性不够好,老感觉这个东西项目中用到需要自己定制
- DevExpress GridControl使用方法总结