题目
Description
挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一 下;再滴三滴,停一下…,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也 算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?
Input
输入数据占一行,由VUL和D组成,其中0< D< VUL< 5000。
Output
请输出挂完盐水需要的时间。
Sample Input
10 1
Sample Output
13
代码块
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cn = new Scanner(System.in);
int vul = cn.nextInt();
int d = cn.nextInt();
int sum = 0;
int i,counts= 0;
for(i =1;;i++){//进行循环模拟水滴
if(sum+i*d<vul){//进行是否是最后一滴判断
sum+=i*d;
counts++;
}
else{
break;
}
}
if(vul%d!=0)//进行判断是否需要,加一秒时间
vul= vul/d+counts+1;
else vul = vul/d+counts;
System.out.println(vul);
}
}