uva 573 The Snail
2013-09-24 20:41
429 查看
一道简单题目,把题目的逻辑分析清楚,模拟爬行的过程就行了。
#include <stdio.h> void func(int h, int u, int d, int f) { /* h---井的高度 u---第一个白天能够爬的高度 d---晚上下滑的高度 f---疲劳因子 */ double delete_height; delete_height = u*(f/100.0); double cur_height, cur_climb_height; int day; if(d > u) { if(u > h) { printf("success on day 1\n"); return; } else { printf("failure on day 1\n"); return; } } else if(d == u) { if(u > h) { printf("success on day 1\n"); return; } else { printf("failure on day 2\n"); return; } } else { cur_height = u; cur_climb_height = u; day = 1; while(1) { if(cur_height > h) { printf("success on day %d\n", day); return; } cur_height -= d; if(cur_height < 0) { printf("failure on day %d\n", day); return; } cur_climb_height -= delete_height; if(cur_climb_height < 0) cur_climb_height = 0; cur_height += cur_climb_height; day ++; } } } int main(void) { int h, u, d, f; while(1) { scanf("%d %d %d %d", &h, &u, &d, &f); if(!h) break; func(h, u, d, f); } return 0; }
相关文章推荐
- UVa 573 - The Snail
- UVA 573 The Snail
- Uva 573 - The Snail
- UVA 573 The Snail
- UVa 573 - The Snail
- UVA - 573 The Snail
- uva 573 The Snail
- UVA-573 The Snail
- uva 573 The Snail
- UVa 573 - The Snail
- UVa 573 - The Snail
- UVA 573 The Snail
- UVA 573-The Snail
- UVa 573 - The Snail
- uva 573 The Snail
- UVA - 573 The Snail
- UVa:573 - The Snail
- UVa 573 The Snail
- UVA 573 - The Snail
- UVA 573 The Snail