hdu1302 The Snail



一只蜗牛在H英尺高的底部,想爬到顶端。蜗牛可以在太阳升起的时候爬上U英尺,但是在晚上睡觉的时候会滑下D英尺。蜗牛的疲劳系数为F(百分比),                                                                                                                                                 这意味着蜗牛在每一天都比前一天少爬(F/100*U)英尺                                                                                               【这个地方一直理解错了*(理解成了每天都比前一天少爬[F/100*(前一天爬的高度)])】。                                            问:蜗牛第几天离开井?


int main()
    int day;
    double H,U,D,F;
    double s,sum;

            if(sum>H) break;
            sum = sum-D;
         if(sum>H)  printf("success on day %d\n",day);
        else printf("failure on day %d\n",day);
    return 0;

The Snail


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 each successive day the snail climbs 10% * 3 = 0.3 feet less than it did the previous day. (The distance lost to fatigue is always 10% of the first day's climbing distance.) On what day does the snail leave the well, i.e., what is the first day during which the snail's height exceeds 6 feet? (A day consists of a period of sunlight followed by a period of darkness.) As you can see from the following table, the snail leaves the well during the third day.nnDay Initial Height Distance Climbed Height After Climbing Height After Slidingn1 0 3 3 2n2 2 2.7 4.7 3.7n3 3.7 2.4 6.1 -nYour job is to solve this problem in general. Depending on the parameters of the problem, the snail will eventually either leave the well or slide back to the bottom of the well. (In other words, the snail's height will exceed the height of the well or become negative.) You must find out which happens first and on what day.nnnInputnnThe input file contains one or more test cases, each on a line by itself. Each line contains four integers H, U, D, and F, separated by a single space. If H = 0 it signals the end of the input; otherwise, all four numbers will be between 1 and 100, inclusive. H is the height of the well in feet, U is the distance in feet that the snail can climb during the day, D is the distance in feet that the snail slides down during the night, and F is the fatigue factor expressed as a percentage. The snail never climbs a negative distance. If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day. Regardless of how far the snail climbed, it always slides D feet at night.nnnOutputnnFor each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid back to the bottom) and on what day. Format the output exactly as shown in the example.nnnSample Inputnn6 3 1 10n10 2 1 50n50 5 3 14n50 6 4 1n50 6 3 1n1 1 1 1n0 0 0 0nnnSample Outputnnsuccess on day 3nfailure on day 4nfailure on day 7nfailure on day 68nsuccess on day 20nfailure on day 2

Snail Alice


问题描述 :nnnSnail Alice is a snail indulged in math. One day, when she was walking on the grass, suddenly an accident happened. Snail Alice fell into a bottomless hole, which was deep enough that she kept falling for a very long time. In the end, she caught the lateral wall of the hole and stop falling down. She named the place where she stopped “lucky place” immediately. nnSnail Alice decided to climb up along the wall from the “lucky place”. The first day she climbed up q0 (q is a positive constant integer) metres, but at night when she fell asleep, she fell down q1 metres. She was shocked when she woke up, and she decided to make an extra effort. The second day she finally climbed up q2 metres. To her surprise, she fell down faster because of the tiredness. She fell down q3 metres at night. The longer she climbed up the longer she fell down. But finally, she still climbed out of the hole and slept on the ground. nnnLying on the grass safe, she was curious about a question. How many metres was the “lucky place” down under the ground? She remembered that the sum of the times of her climbing up and falling down is n(of course, n is odd), so the distance between the ground and the “lucky place” must be 1-q+q2-q3+…+(-1)n-1qn-1. Snail Alice simplified that long formula and get a beautiful result: (qn+1)/(q+1). But as a math professor, she wouldn’t stop. She came up with a good problem to test her students. Here is the problem:nnnA function f(n), n is a positive integer, and n nnPassing the MessagennGiven q and n, please calculate the value of f(n).Please note that q and n could be huge. n输入:nnnInput consists of multiple test cases, and ends with a line of “-1 -1 -1”.nFor each test case: nThe first line contains three integers x1, y1 and z1, representing q. q=x1^y1+z1.nThe second line contains two integers: y2 and z2, representing n. n=2^y2+z2.nThe third line contains a single integer P, meaning that what you really should output is the formula’s value mod P. nNote: 0<=x1,y1,z1,y2,z2<=50000, z1>0, 00, 0


  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他