zoukankan      html  css  js  c++  java
  • light oj 1297 Largest Box

    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

    求导 找点

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #define DD double
    using namespace std;
    DD w,l;
    DD f(DD x)
    {
    	return x*(w-2*x)*(l-2*x);
    }
    int main()
    {
    	int t,k,i;
    	scanf("%d",&t);
    	k=1;
    	while(t--)
    	{
    		scanf("%lf%lf",&l,&w);
    		DD b=(-4)*(w+l);
    		DD a=12;
    		DD c=w*l;
    		DD x1=(sqrt(b*b-4*a*c)-b)/(2*a);
    		DD x2=(-sqrt(b*b-4*a*c)-b)/(2*a);
    		printf("Case %d: ",k++);
    		printf("%.7lf
    ",max(f(x1),f(x2)));
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Linux报错:“/bin/bash^M: 坏的解释器
    搭建单向HTTPS
    Wamp Apache 启动失败检测方法
    Excel 日常操作
    apache https 双向认证
    android搭建
    我身为程序员踩过的坑
    windows 2008 安装 apache + mysql + php
    Svn
    工具软件类
  • 原文地址:https://www.cnblogs.com/tonghao/p/4949785.html
Copyright © 2011-2022 走看看