zoukankan      html  css  js  c++  java
  • lightoj--1294--Largest Box(三分)

    Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

    Submit Status

    Description

    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

    3

    2 10

    3.590 2.719

    8.1991 7.189

    Sample Output

    Case 1: 4.513804324

    Case 2: 2.2268848896

    Case 3: 33.412886

    Source

    Problem Setter: Shahriar Manzoor
    Special Thanks: Jane Alam Jan (Description, Solution, Dataset)


    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    double w,l;
    double v(double x)
    {
    	return (l-2*x)*(w-2*x)*x;
    }
    double san(double l,double r)
    {
    	double mid,mm;
    	while(r-l>1e-10)
    	{
    		mid=(l+r)/2;
    		mm=(mid+r)/2;
    		if(v(mid)>=v(mm)) //谁大在谁的附近找 
    			r=mm;
    		else
    			l=mid;
    	}
    	return mid;
    }
    int main()
    {
    	int t;
    	int Case=1; 
    	scanf("%d",&t);
    	while(t--)
    	{ 
    		scanf("%lf%lf",&w,&l);
    		double num=san(0,min(w,l)/2);
    		printf("Case %d: %lf
    ",Case++,v(num));
    	}
    	return 0;
    }


  • 相关阅读:
    oracle数据库的乱码问题解决方案
    @HTML.checkboxFor()用法
    存储过程实现登录(.net)
    .net中大数据的处理
    xml总结
    获取指定日期是当前月的第几周
    JS中正则方法的使用
    获取指定日期的前一天日期
    通过Oracle函数实现.NET String.Format函数的简单版
    ReportViewer实现多语言
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273744.html
Copyright © 2011-2022 走看看