UVa-573

这道题目开始提交多次都出错,后来试了一下就A了,也没对代码进行什么改变,非常费解。还想给UVa提一个建议,为什么不能看到自己提交以后的代码?如果像POJ可以看的话,对自己对比自己的代码,找到错误很有帮助!

还要注意一点的是:判断Success还是Failure的时候,是当前高度height > heightOfWell,height < 0, 而不是 <=, >=. 题目中的原句是 In other words, the snail's height will exceed the height of the well or become negative

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define  LOCAL
float h, u, d, f;// h - height, u - distance climb, d - slide, f - fatigue

int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%f%f%f%f", &h, &u, &d, &f);
	while (h != 0)
	{
		float speed = u, h_t = 0, delta = u * f/100.0;
		int iter = 0, flagSuccess = 0, flagFail = 0;
		while ((!flagFail)&&(!flagSuccess))
		{
			iter++;
			speed = (speed > 0)?speed:0;
			if (h_t + speed > h)
				flagSuccess = 1;
			else if (h_t + speed - d < 0)
				flagFail = 1;
			h_t = h_t + speed - d;
			speed -= delta;
		}
		if (flagFail)
			printf("failure on day %d\n", iter);
		if (flagSuccess)
			printf("success on day %d\n", iter);
		scanf("%f%f%f%f", &h, &u, &d, &f);
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值