zoukankan      html  css  js  c++  java
  • 1297

    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,三分写一下就过了。。。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #define mem(x,y) memset(x,y,sizeof(x))
     7 #define ZR (4*W+4*L)*(4*W+4*L)-48*W*L
     8 using namespace std;
     9 const int INF=0x3f3f3f3f;
    10 double L,W;
    11 double js(double x){
    12     return x*(L-2*x)*(W-2*x);
    13 }
    14 double sf(double l,double r){
    15     double mid,mm;
    16     while(r-l>1e-10){
    17         mid=(l+r)/2;
    18         mm=(mid+r)/2;
    19         if(js(mid)>=js(mm))r=mm;
    20         else l=mid;
    21     }
    22     return mid;
    23 }
    24 int main(){
    25     int T,flot=0;
    26     scanf("%d",&T);
    27     while(T--){
    28         scanf("%lf%lf",&L,&W);
    29         double x=sf(0,min(L,W)/2);
    30     //    printf("%f
    ",x);
    31         printf("Case %d: %lf
    ",++flot,js(x));
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    AC自动机
    HDU
    2020牛客寒假算法基础集训营3 B 牛牛的DRB迷宫II
    POJ 3784 Running Median【维护动态中位数】
    CodeForces
    HDU 2444 The Accomodation of Students【二分图最大匹配问题】
    POJ 1201 Intervals【差分约束】
    POJ 2976 Dropping tests【0/1分数规划模板】
    2019牛客暑期多校训练营(第七场)A.String【最小表示法】
    POJ 1287 Networking【kruskal模板题】
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4947258.html
Copyright © 2011-2022 走看看