题目大意:有一只蜗牛位于深一个深度为h米的井底,它白天向上爬u米,晚上向下滑d米,由于疲劳原因,蜗牛白天爬的高度会比上一天少f%(总是相对于第一天),如果白天爬的高度小于0,那么这天它就不再向上爬,问这只蜗牛在几天爬出井口或滑下井底。
很直接的题,就是纠结于当蜗牛白天不爬的时候,下一天它是继续不爬还是向上爬u米,这个题的意思应该是以后白天都不再向上爬。还有就是注意边界,成功(>h)和失败(<0)。

1 #include <cstdio> 2 3 int main() 4 { 5 #ifdef LOCAL 6 freopen("in", "r", stdin); 7 #endif 8 int height, up, down, f; 9 while (scanf("%d%d%d%d", &height, &up, &down, &f) && height) 10 { 11 double diff = up * f / 100.0; 12 double pos = 0, dis = up; // dis is the distance of climb on current day 13 int day = 0; 14 while (true) 15 { 16 day++; 17 pos += dis; 18 if (pos > height) 19 { 20 printf("success on day %d ", day); 21 break; 22 } 23 if (dis > 0) dis -= diff; 24 if (dis < 0) dis = 0; 25 pos -= down; 26 if (pos < 0) 27 { 28 printf("failure on day %d ", day); 29 break; 30 } 31 } 32 } 33 return 0; 34 } 35
本来说要练习DP的,可是忽然又想系统的看一下Competitive Programming 1,发现上面的分类还是不错的,比《算法竞赛入门经典》更细,于是就从头开始了...,是不是太三心二意了?-_-|| 本来是打算好好做白书的习题的,只是那本书就给了一大堆习题,也没分类,算了,结合着看吧,希望最后不要什么都没干成...先从starred problems的开始吧,剩下的题可以以后在做,毕竟原来也做了一些水题了,现在主要想在算法方面提高一下,而不是去刷排名。