电子奥林匹克:蛋糕。给出错误的答案
E-olymp: Cake. Giving Wrong Answer
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
小时。
我的做法是错误的。
只是我必须使用这个规则:
t1
hours/cake = 1/t1
cakes/hour.
三个人都在一小时内吃了 1/t1+1/t2+1/t3
个蛋糕。
在 h 小时内,他们吃了 h(1/t1+1/t2+1/t3)
个蛋糕。
吃一整块蛋糕的时间必须满足h(1/t1+1/t2+1/t3)=1
或h=1/(1/t1+1/t2+1/t3).
代码为:
double t1, t2, t3;
scanf("%lf %lf %lf", &t1, &t2, &t3);
double ans=1/((1/t1)+(1/t2)+(1/t3));
printf("%.2lf\n", ans);
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
小时。
我的做法是错误的。
只是我必须使用这个规则:
t1
hours/cake = 1/t1
cakes/hour.
三个人都在一小时内吃了 1/t1+1/t2+1/t3
个蛋糕。
在 h 小时内,他们吃了 h(1/t1+1/t2+1/t3)
个蛋糕。
吃一整块蛋糕的时间必须满足h(1/t1+1/t2+1/t3)=1
或h=1/(1/t1+1/t2+1/t3).
代码为:
double t1, t2, t3;
scanf("%lf %lf %lf", &t1, &t2, &t3);
double ans=1/((1/t1)+(1/t2)+(1/t3));
printf("%.2lf\n", ans);