首页 > 其他 > 详细

LightOJ - 1297 - Largest Box(数学)

时间:2019-11-12 14:07:30      阅读:74      评论:0      收藏:0      [点我收藏+]

链接:

https://vjudge.net/problem/LightOJ-1297

题意:

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.

思路:

三次函数。
求导,根据图像求二次函数的较小x解即可。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>

using namespace std;
typedef long long LL;
const int INF = 1e9;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;

int main()
{
    int t, cnt = 0;
    double l, w;
    scanf("%d", &t);
    while(t--)
    {
        printf("Case %d: ", ++cnt);
        scanf("%lf%lf", &l, &w);
        double res = (4*(l+w)-sqrt(16*(l+w)*(l+w)-4*12*(l*w)))/24.0;
        printf("%lf\n", res*(l-2*res)*(w-2*res));
    }

    return 0;
}

LightOJ - 1297 - Largest Box(数学)

原文:https://www.cnblogs.com/YDDDD/p/11841397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!