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 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 |
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 |
题解:方程式列一下,因为是3次方,一看就是求极值的,但是注意范围是0,min(w,h)/2,三分写一下就过了。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
#define ZR (4*W+4*L)*(4*W+4*L)-48*W*L
using namespace std;
const int INF=0x3f3f3f3f;
double L,W;
double js(double x){
return x*(L-*x)*(W-*x);
}
double sf(double l,double r){
double mid,mm;
while(r-l>1e-){
mid=(l+r)/;
mm=(mid+r)/;
if(js(mid)>=js(mm))r=mm;
else l=mid;
}
return mid;
}
int main(){
int T,flot=;
scanf("%d",&T);
while(T--){
scanf("%lf%lf",&L,&W);
double x=sf(,min(L,W)/);
// printf("%f\n",x);
printf("Case %d: %lf\n",++flot,js(x));
}
return ;
}
1297 - Largest Box(三分)的更多相关文章
- light oj 1297 Largest Box
1297 - Largest Box PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In t ...
- LightOJ - 1297 - Largest Box(数学)
链接: https://vjudge.net/problem/LightOJ-1297 题意: In the following figure you can see a rectangular ca ...
- LightOJ - 1297 Largest Box LightOJ(一元三次方程求极大值)
题目链接:https://vjudge.net/contest/28079#problem/K 题目大意:给你一个长为L,宽为W的纸片,四个角剪掉边长为x的正方形,如下图所示,然后折成一个无盖的纸盒, ...
- lightoj 1297(三分)
传送门:Largest Box 题意:长度为L宽度为W的纸四个角去掉x*x的正方形,然后形成一个长方体,问能组成长方体的最大体积为多少. 分析:三分x求最值. #include <cstdio& ...
- lightoj--1294--Largest Box(三分)
Largest Box Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu Submit Sta ...
- uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)
题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...
- UVA10215The Largest/Smallest Box(小数精度)
本身很容易却因为评测机有毒的一道题,,,看网上题解说最后一个答案要加一个很小的数才能AC,据说是因为没有speci judge #include <iostream> #include & ...
- HDU 4717The Moving Points warmup2 1002题(三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4717 The Moving Points (三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- zen-coding for notepad++,前端最佳手写代码编辑器
zen-Coding是一款快速编写HTML,CSS(或其他格式化语言)代码的编辑器插件,这个插件可以用缩写方式完成大量重复的编码工作,是web前端从业者的利器. zen-Coding插件支持多种编辑器 ...
- iOS 7 标签栏控制器进行模态视图跳转后变成透明
要解决此问题,需要设置tabBar的如下属性: self.tabBar.translucent = NO;
- Determine If Two Rectangles Overlap
判断相交的情况比较复杂,所以从判断不相交的角度考虑. ! (P1.y < P4.y || P1.x > P4.x || P2.y > P3.y || P2.x < P3.x)
- C++重载赋值运算符
这是一道C++的面试题,下面在这篇博客中分析一下这个问题.先上题目: //题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: ...
- cocos2d-x中的CCScrollView滑动体验不佳
在最近的项目中,使用了Cocos2d-x (2.2.0版本)提供的CCScrollView来拖动一个比较大的画面,但是发现滑动体验非常不佳, 手指离开屏幕后,滑动没有惯性,一个不算太大的画面,要滑动好 ...
- 使用CarrierWave上传图片时,多版本文件名的统一
第一次使用CarrierWavewe做上传,不能不说,虽然Rails已经把上传变得超简单了,而CarrierWave则是把上传变成了一种享受,特别是做图片上传,现在这年代,图片展示平台已经不仅仅是电脑 ...
- javascript 字符串方法传参
javascript 字符串方法传参由于嵌套的单引号,双引号过多.有点混乱.. 正确方法如下: ' <td align="left"><input type= ...
- python利用utf-8编码判断中文英文字符(转)
下面这个小工具包含了判断unicode是否是汉字.数字.英文或者其他字符,全角符号转半角符号,unicode字符串归一化等工作. #!/usr/bin/env python # -*- coding: ...
- TCP编程的一个小例子
TCP程序的服务器端与客户端的流程图 例子:服务器端等待客户端连接,若连接成功,则用户可以通过客户端向服务器端发送任意字符串,服务器端在收到字符串后,输出相关信息,在把接受到的字符串重新发生给客户端. ...
- Node.mysql
mysql为常用数据库,下面简单记录在nodejs中操作mysql数据库的简单实现. 环境: nodejs4.2.2 mysql5.7.12 win7 参考资料: npm mysql 代码 var m ...