zoukankan      html  css  js  c++  java
  • (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
    ",day);
    38         else printf("failure on day %d
    ",day);
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    NGUI UIEventListener
    Unity3d NGUI Panel 滑动菜单
    NGUI 密码输入框
    Unity3d 时间差
    Unity3d 添加组件脚本和建菜单
    c# [HideInInspector] 属性
    c# [System.Serializable]
    Activity 生命周期
    Unity3d OnApplicationPause与OnApplicationFocus
    C# 中 Struct 与 Class 的区别
  • 原文地址:https://www.cnblogs.com/ACDoge/p/6135516.html
Copyright © 2011-2022 走看看