(HDU)1302 -- The Snail(蜗牛)

题目链接:http://vjudge.net/problem/HDU-1302

分析:这题的限制要求很多,一天分为白天和黑夜。并不能直接用上升-下降作为一天变化量(万一白天就出去了呢?)。

一开始做的时候初始位置要设置double型的0,我写成了int型,郁闷了半天。

要注意up的距离不可能是负的,就算很疲劳。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <cstdlib>
 8
 9 using namespace std;
10
11 int main()
12 {
13     double  height,up,down,factor,delta;
14     while(~scanf("%lf",&height))
15     {
16         if(height==0) break;
17         scanf("%lf %lf %lf",&up,&down,&factor);
18         int day=0,flag=0;
19         double place=0,first=up;
20         delta=(first*factor*0.01);
21         for(day=1;;day++)
22         {
23             if(up>=0) place+=up;
24             if(place>height)
25             {
26                 flag=1;
27                 break;
28             }
29             place-=down;
30             if(place<0)
31             {
32                 flag=0;
33                 break;
34             }
35             if(up>=0) up-=delta;
36         }
37         if(flag) printf("success on day %d\n",day);
38         else printf("failure on day %d\n",day);
39     }
40     return 0;
41 }
时间: 2024-12-29 12:39:21

(HDU)1302 -- The Snail(蜗牛)的相关文章

HDU 1302 The Snail(简单数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1302 Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail

杭电 HDU ACM 1302 The Snail

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1783    Accepted Submission(s): 1252 Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The s

hdu 1302(The Snail)

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1461    Accepted Submission(s): 1069 Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The s

洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails

题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总是从棋盘的左上角出发.棋盘上有空的格子(用“.”来表示)和B 个路障(用“#”来表示). 下面是这种表示法的示例棋盘: 萨丽总是垂直(向上或者向下)或水平(向左或者向右)地走.她可以从出发地(总是记作A1 )向下或者向右走.一旦萨丽选定了一个方向,她就会一直走下去.如果她遇到棋盘边缘或者路障,她就停下来,并且转过90 度.她不可能离开棋盘,或者走进路障当中.并且,萨丽从不跨过

洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails(不明原因的scanf错误)

P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总是从棋盘的左上角出发.棋盘上有空的格子(用“.”来表示)和B 个路障(用“#”来表示). 下面是这种表示法的示例棋盘: 萨丽总是垂直(向上或者向下)或水平(向左或者向右)地走.她可以从出发地(总是记作A1 )向下或者向右走.一旦萨丽选定了一个方向,她就会一直走下去.如果她遇到棋盘边缘或者路障,她就停下来,并且

The Snail(杭电 1302)

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1477    Accepted Submission(s): 1081 Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The s

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

杭电ACM 蜗牛出井

Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on ea