lightOJ 1297 - Largest Box 【数学题】
2015-11-08 18:58
267 查看
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.
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/15/1197295dfb2fd56d1c65dda60dff6410.png)
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.
Each case starts with a line containing two real numbers L and W (0 < L, W < 100).
PROBLEM SETTER: SHAHRIAR MANZOOR
SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)
思路:
由题意知体积等于(L-2*x)*(W-2*x)*x的最大值,且最大值肯定存在,那么就直接对它求导,然后由一元三次方程的图像可以知道,应该取另它等于0得到的较小的解,(这个不用考虑边界100,因为50取不到,所以就不可能是最大值的x的取值),只考虑一个就行了!不用想太多,就只找一个极大值(也就是最大值)就行了!
代码如下:
![]() | PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
the black dotted lines. Then the card is folded along the magenta lines to make a box without a cover.
![](https://oscdn.geek-share.com/Uploads/Images/Content/201912/15/1197295dfb2fd56d1c65dda60dff6410.png)
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 | 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 |
SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)
思路:
由题意知体积等于(L-2*x)*(W-2*x)*x的最大值,且最大值肯定存在,那么就直接对它求导,然后由一元三次方程的图像可以知道,应该取另它等于0得到的较小的解,(这个不用考虑边界100,因为50取不到,所以就不可能是最大值的x的取值),只考虑一个就行了!不用想太多,就只找一个极大值(也就是最大值)就行了!
代码如下:
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; double l,w; double maxn; double V(double x) { double v=(l-2*x)*(w-2*x)*x; return v; } int main() { int T; scanf("%d",&T); int N=T; while(T--) { scanf("%lf%lf",&l,&w); double x=(4*(w+l)-sqrt(16*(w+l)*(w+l)-4*12*(w*l)))/24.0; printf("Case %d: ",N-T); printf("%lf\n",V(x)); } return 0; }
相关文章推荐
- 信息安全系统设计基础第九周学习总结——20135308
- 人人生而平等,不可轻视任何一个人
- React Native技术栈学习路径
- Ubuntu下配置samba实现文件夹共享
- Android SDK Manager国内无法更新的解决方案
- 黑马程序员——java基础---反射、正则
- Android实践项目汇报(一)
- 【C】【笔记】《C语言深度剖析》第二章 符号
- Zookeeper在Windows上安装
- 马尔可夫链
- scrollView上下滚item淡入淡出效果
- canvas 下载
- 工厂模式(智能指针方式)
- 关于OC中快速枚举forin和for循环的一点区别
- 数据结构基础:栈和队列
- ListView的属性及方法详解
- 自由之路
- JAVA课程作业06
- 【C】【笔记】《C语言深度剖析》第一章 关键字
- 《大道至简》第六章读后感