若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1595: The Largest/Smallest Box..

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,267

题目描述

The following figure shows a rectangular card of width W, length L, and thickness 0. Four x x x squares are cut from the four corners of the card shown by the dotted lines. The card is then folded along the dashed lines to make a box without a cover.

Given the width and height of the box, find the values of x for which the box has maximum and minimum volume.

输入

The input file contains several lines of input. Each line contains two positive floating point numbers L ( 0 < L < 10, 000) and W ( 0 < W < 10, 000), which indicate the length and width of the card, respectively.

输出

For each line of input, give one line of output containing two or more floating point numbers separated by a single space. Each floating point number should contain three digits after the decimal point. The first number indicates the value which maximizes the volume of the box, while the subsequent values (sorted in ascending order) indicate the cut values which minimize the volume of the box.

样例输入

1 1
2 2
3 3


样例输出

0.167 0.000 0.500
0.333 0.000 1.000
0.500 0.000 1.500


参考代码

#include <stdio.h>
#include <math.h>
double eps=1e-7;
int main() 
{
    double ll,ww;
    while(scanf("%lf%lf",&ll,&ww)==2) 
    {
        double a=12;
        double b=-4*(ll+ww);
        double c=ll*ww;
        double x=(-b-sqrt(b*b-4*a*c))/(2*a),x2=ll>ww?ww/2:ll/2;
        printf("%.3lf %.3lf %.3lfn",x,0.0,x2+eps);
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Skip Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist