刚开始审题不清,成功WA了好几次
哎还是要好好读题啊~~~
此题有几个注意点:
1.我在一回合内喝药,对面怪也会打我,所以一回合可以加(c1-a2)的血量
2.我总是比怪物多行动一个回合!!!我想赢的话!
import java.util.Scanner;
//注:我总是比对面的怪物多行动一次!!!
public class Main20 {
public static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
while(sc.hasNext()) {
int h1=sc.nextInt();
int a1=sc.nextInt();
int c=sc.nextInt();
int h2=sc.nextInt();
int a2=sc.nextInt();
int i=1;
//判断我在多少个回合可以杀死怪物:
while(i*a1<h2)
i++;
//判断怪物是否可以在(i-1)个回合杀死我
if((i-1)*a2<h1) {
System.out.println(i);
while(i-->0)
System.out.println("STRIKE");
}
//如果怪物正好在我的i回合(即我最后一次攻击之前)可以杀死我
//那么由于c1>a2,所以我只需喝一次药
else if((i-1)*a2==h1) {
System.out.println(i+1);
System.out.println("HEAL");
while(i-->0)
System.out.println("STRIKE");
}
//这个就是如果前面两种都不满足,那么我可以先喝药到可以撑过怪物的(i-1)轮次攻击
else {
int h=1;
int result=c+h1-a2;
while(result<=(i-1)*a2) {
result=result+c-a2;
h++;
}
System.out.println(h+i);
while(h-->0)
System.out.println("HEAL");
while(i-->0)
System.out.println("STRIKE");
}
}
}
}