严正声明:转载请注明出处!!!
题目描述:
小红在一个游戏里杀怪,这是个回合制的游戏,小红和两只怪物相遇了。第一只怪物有a血量,第二只怪物有b血量。
小红有两个技能:
第一个技能叫火球术,效果是对单体怪物造成x伤害
第二个技能叫烈焰风暴,效果是对每只怪物造成y伤害
小红想知道,自己最少使用多少次技能,可以击杀这两只怪物?(当怪物血量小于等于0·时,视为被击杀)
输入描述:
四个正整数a,b,x,y,用空格隔开。
1≤a,b,x,y≤20
输出描述:
小红使用技能的最少次数
示例1:
输入
5 2 3 1
输出
3
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 两只怪兽的血量
int b = sc.nextInt();
int a = sc.nextInt();
//伤害指数
// 单体
int x = sc.nextInt();
// 每只
int y = sc.nextInt();
int count = 0;
while (a > 0 && b > 0){
if(Math.min(a, y) + Math.min(b, y) >= Math.min(Math.max(a, b), x)){
a -= y;
b -= y;
count++;
}else{
if(a >= b){
a -= x;
count++;
}else{
b -= x;
count++;
}
}
}
while (a > 0){
if(x >= y){
a -= x;
count++;
}else{
a -= y;
count++;
}
}
while (b > 0){
if(x >= y){
b -= x;
count++;
}else{
b -= y;
count++;
}
}
System.out.println(count);
}
}