gpt4 book ai didi

c++ - E-olymp : Cake. 给出错误答案

转载 作者:行者123 更新时间:2023-11-30 05:41:15 24 4
gpt4 key购买 nike

Cake这是一道 e-olymp 编程题。

In honor of the birth of an heir Tutti royal chef has prepared a huge cake, that was put on the table for Three Fat Man. The first fat man can eat the cake by himself for t1 hours, second - for t2 hours, and the third - for t3 hours.

For what time can the cake be eaten simultaneously by all three fat men?

当我在正常的 Gnu C++ 中提交时,它给出了 27% 的准确结果,而当我在 Gnu C++ 4.7.1 中提交时,它给出了 8%结果准确??问题是什么??是我的错吗??请帮忙。

我的代码:

#include<iostream>
#include<cstdio>

using namespace std;

int main()
{

double t1, t2, t3;
scanf("%lf %lf %lf", &t1, &t2, &t3);

double ans=(t1/3.0)+(t2/3.0)+(t3/3.0);
ans=(ans/3.0);
printf("%.2lf\n", ans);
return 0;

}

最佳答案

你的逻辑是错误的。

想象一下,第一个人可以在 1 小时内吃完整个蛋糕。

如果另外两个人帮忙,蛋糕会更快吃完。 不到一小时

这是模拟该场景的输入。

1 999 999

你的程序计算所需的时间为

((1/3.0)+(999/3.0)+(999/3.0)/3.0)

那是 444.33 小时。

关于c++ - E-olymp : Cake. 给出错误答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31216018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com