周六 5.9 e题

题目

Your friend Claire has dragged you along to a speedcubing event that is happening in Eindhoven. These events are all about solving the Rubik’s cube and similar twisty puzzles as quickly as possible. The attendants of the event can enter into various competitions based on the type and size of the puzzle, and there are even special competitions where the puzzles need to be solved one-handed or blindfolded.

Claire is competing in the most popular competition: speedsolving the 3×3×3 Rubik’s cube, pictured on the right. Each contestant needs to solve the cube five times, each time with a different random scramble. After all solves are completed, the best and the worst times are discarded and the final score is the average of the remaining three times. The contestant with the smallest final score wins.

Claire has done well in the competition so far and is among the contenders for the overall victory. All the other contestants have already finished their five solves, but Claire has one solve remaining. By looking at the final scores of the other contestants, she has deduced her own target final score. As long as her final score is less than or equal to this target score, she will be declared the overall winner. Is it possible for her to win the competition, and if so, what is the worst time she can have on her last solve in order to do so?

The input consists of:

• One line with four real numbers t1, t2, t3 and t4, the times Claire got on her first four solves.

• One line with a real number t, Claire’s target final score, the worst final score she can have in order to be declared the overall winner.

Each number is between 1 and 20, inclusive, and is given with exactly two decimal places.

If it is not possible for Claire to win the event, output “impossible”. If she will win regardless of the time she gets on her last solve, output “infinite”. Otherwise, output the worst time she can have on her last solve in order to be declared the overall winner. Output the number to exactly two decimal places.

易错点

本题为精度问题,在判断时加上1e-5。
我想将每一个数乘100将其转化为整数进行计算,但是依然错了,目前正在找原因。

代码

#include
#include
#include
using namespace std;
int main()
{
double a[4],b;
double good,bad;
double fen;
cin>>a[0]>>a[1]>>a[2]>>a[3];
cin>>b;
sort(a,a+4);
bad=(a[1]+a[2]+a[3])/3;
good=(a[0]+a[1]+a[2])/3;
if(b>=bad+1e-5)
cout<<“infinite”;
if(b<good+1e-5)
cout<<“impossible”;
if(b>=good+1e-5&&b<bad+1e-5)
{
fen=b*3-a[1]-a[2];
printf("%.2f",fen);
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值