0
点赞
收藏
分享

微信扫一扫

HDU 1408 盐水的故事(模拟)


盐水的故事


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17297    Accepted Submission(s): 4229



Problem Description

挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?



Input

输入数据包含多个测试实例,每个实例占一行,由VUL和D组成,其中 0<D<VUL<5000。




Output

对于每组测试数据,请输出挂完盐水需要的时间,每个实例的输出占一行。



Sample Input

10 1

Sample Output


13


Author

lcy


Source

​​杭电ACM集训队训练赛(IV)  ​​


题解:模拟一下

AC代码:


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<time.h>
typedef long long LL;
using namespace std;
int main()
{
double n,m;
while(cin>>n>>m)
{
int time=0;
int t=1;
int flag=0;
while(flag==0)
{
for(int i=1;i<=t;i++) //t为水滴数
{
n=n-m;
++time;
if(n<=0){
flag=1;
break;
}
}
if(flag==1)break;
++t; //下一次滴的水滴+1
time++; //停一次
}
printf("%d\n",time);
}
return 0;
}


AC:模拟:

函数名: ceil

用 法: double ceil(double x);


功 能: 返回大于或者等于指定表达式的最小整数


头文件: ​​math.h​​


返回数据类型:double

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
using namespace std;
int main( )
{
double v,d;
int s,n;
while( scanf( "%lf%lf",&v,&d ) != EOF )
{
s = 0,n = 1;
while( v / d > n )//(v>n*d)就不能过
{
v -= n*d;
s += n;
s++;
n++;
}
s += ceil( v/d );
printf( "%d\n",s );
}
return 0;
}



举报

相关推荐

0 条评论