HDU-IMNU集训之不及AC送我情~:Climbing Worm-新学到一个函数

来源:互联网 发布:我的世界java问题 编辑:程序博客网 时间:2024/05/01 21:53
题目大致意思为:
一只小虫要从井底爬出
井深为n,上升一秒走u,休息一秒下降d.
可以这样考虑:
每两秒走(u-d);
无论走了多少个(u-d),而最后一秒只走了u.
可以说最后一秒可以一步到达。
#include<iostream>#include<iomanip>#include<stdio.h>#include<algorithm>#include<cmath>//ceil()向“大”去整 #include<cstring>//strstr()using namespace std; int main (){    double n,u,d;    int temp;     while( cin>>n>>u>>d )    {          if(n==0) break;                         temp=int(ceil( (n-u)/(u-d) ));//起初我只是对结果四舍五入           cout<<temp*2+1<<endl;         //后来明白没除尽的也算走了一个(u-d)     }    system("pause");         return 0;}
题目没有考虑d==0的情况···

0 0
原创粉丝点击