BoBo买了一箱酸奶,里面有n盒未打开的酸奶,KiKi喜欢喝酸奶,第一时间发现了酸奶。KiKi每h分钟能喝光一盒酸奶,并且KiKi在喝光一盒酸奶之前不会喝另一个,那么经过m分钟后还有多少盒未打开的酸奶?
BoBo买了一箱酸奶,里面有n盒未打开的酸奶,KiKi喜欢喝酸奶,第一时间发现了酸奶。KiKi每h分钟能喝光一盒酸奶,并且KiKi在喝光一盒酸奶之前不会喝另一个,那么经过m分钟后还有多少盒未打开的酸奶?
多组输入,每组输入仅一行,包括n,h和m(均为整数)。输入数据保证m <= n * h。
针对每组输入,输出也仅一行,剩下的未打开的酸奶盒数。
8 5 16
4
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//总数
int n = scanner.nextInt();
//一瓶所用时间
int h = scanner.nextInt();
//经过时间
int m = scanner.nextInt();
//喝掉的酸奶总数=已经喝掉的(m/h)+喝了但没喝完的(m%h);
int total = m % h > 0 ? m/h+1:m/h;
int odd = n - total;
System.out.println(odd);
}
} import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan =new Scanner(System.in);
int n =scan.nextInt();
int h =scan.nextInt();
int m =scan.nextInt();
double m1=m;
double h1=h;
double c=m1/h1;
double d =n-Math.ceil(c);
System.out.println((int)d);
}
} 首先判断分钟数能不能整除5,
如果能整除的话,
所喝的瓶数就是:分钟数/5,
否则就是:分钟数/5+1
剩下的=总数-所喝的
import java.util.*;
public class Main
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt())
{
int n=sc.nextInt();
int h=sc.nextInt();
int m=sc.nextInt();
int f=(m%h==0?m/h:m/h+1);
int result=n-f;
System.out.println(result);
}
}
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, h, m;
int t;
cin >> n >> h >> m;
t = h;
if(m <= (h * n)){
n -= 1;
while(m - t > 0){
n--;
t += h;
}
cout << n << endl;
}
return 0;
} t是一个时间变量,m <= h * n 是题目中给的判断关系。