10215 - The Largest/Smallest Box ...

这道题10.03%的提交通过率真不是盖的……自己也忽忽悠悠的错了n次……

这道题乍一看挺简单了,刚开始自己先求出极大值和极小值,然后比较,但老是不对。后来发现最小值在0min(l/2, w/2)出取得,而不是0和极小值处=_=

但这样还是不对,在四舍五入的时候要加一个eps偏移量。。。。

这样就可以过了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const double eps = 1e-12;
double w, l;
double sq, root1, root2, a, b;
int sig(double x)
{
    return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1);
}
double fun(double x)
{
    return x * (l - 2 * x) * (w - 2 * x);
}
int main()
{
    //freopen("input.txt", "r", stdin);
    double v1, v2, r;
    while(scanf("%lf %lf", &l, &w) == 2){
        a = l + w;
        b = l * w;
        sq = 4.0 * sqrt(l * l + w * w - l * w);
        root1 = (4 * a - sq) / 24.0;
        r = root2 = min(w / 2.0, l / 2.0);
        v1 = fun(root1);
        v2 = fun(root2);

        if(sig(root1 - root2) < 0){
            if(sig(v1 - v2) == 0){
                printf("%.3lf %.3lf", root1, root2);
            }else if(sig(v1 - v2) > 0)
                printf("%.3lf", root1 + eps);
            else printf("%.3lf", root2 + eps);
        }else printf("%.3lf", root2 + eps);
        root1 = 0;
        root2 = r;
        printf(" %.3lf %.3lf\n", root1 + eps, root2 + eps);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/home/fujiayu/esp/esp-idf/tools/check_python_dependencies.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html import pkg_resources Executing action: flash Running ninja in directory /home/fujiayu/esp/hello_world/build Executing "ninja flash"... [1/5] cd /home/fujiayu/esp/hello_world.../esp/hello_world/build/hello_world.bin hello_world.bin binary size 0x31ee0 bytes. Smallest app partition is 0x100000 bytes. 0xce120 bytes (80%) free. [1/1] cd /home/fujiayu/esp/hello_world..._world/build/bootloader/bootloader.bin Bootloader binary size 0x5290 bytes. 0x2d70 bytes (35%) free. [2/3] cd /home/fujiayu/esp/esp-idf/com...nents/esptool_py/run_serial_tool.cmake esptool esp32s3 -p /dev/ttyACM0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin esptool.py v4.6.2 Serial port /dev/ttyACM0 A fatal error occurred: Could not open /dev/ttyACM0, the port doesn't exist CMake Error at run_serial_tool.cmake:66 (message): /home/fujiayu/.espressif/python_env/idf5.2_py3.8_env/bin/python;;/home/fujiayu/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32s3 failed. FAILED: CMakeFiles/flash cd /home/fujiayu/esp/esp-idf/components/esptool_py && /usr/bin/cmake -D IDF_PATH=/home/fujiayu/esp/esp-idf -D "SERIAL_TOOL=/home/fujiayu/.espressif/python_env/idf5.2_py3.8_env/bin/python;;/home/fujiayu/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32s3" -D "SERIAL_TOOL_ARGS=--before=default_reset;--after=hard_reset;write_flash;@flash_args" -D WORKING_DIRECTORY=/home/fujiayu/esp/hello_world/build -P /home/fujiayu/esp/esp-idf/components/esptool_py/run_serial_tool.cmake ninja: build stopped: subcommand failed. ninja failed with exit code 1, output of the command is in the /home/fujiayu/esp/hello_world/build/log/idf_py_stderr_output_21690 and /home/fujiayu/esp/hello_world/build/log/idf_py_stdout_output_21690
07-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值