已知问题,已知你场上有1血,2血,6血生物各一个,对面有一个16/16的克苏恩,你的血量大于16血,求克苏恩清场的概率
import java.util.Random;
public class Kesuen {
int deadNumber = 0;
int qingchang = 0;
int num = 4;
public void update(){
for(int i=0;i<1000000;i++){
xunhuan();
}
System.out.print("你清场了"+qingchang+"次");
System.out.print("你挂了"+deadNumber+"次");
}
public int updateNum(int a,int b, int c){
num = 1;
if(a > 0){
num++;
}
if(b > 0){
num++;
}
if(c > 0){
num++;
}
return num;
}
public void xunhuan(){
int[] a ={18,6,2,1};
boolean isLive = true;
boolean hasMissile = true;
int missile = 16;
boolean qing = false;
while(isLive && hasMissile){
Random random = new Random();
int flag = random.nextInt(num);
a[flag] = a[flag] - 1;
missile--;
if(a[0] == 0){
deadNumber++;
isLive = false;
return;
}
if(!qing){
if(a[1] == 0&&a[2]!=0){
a[1] = a[2];
a[2] = a[3];
a[3] = 0;
}else if(a[1] == 0&&a[2]==0){
qingchang++;
qing = true;
}
if(a[2] == 0 ){
a[2] = a[3];
a[3] = 0;
}
}
if(missile == 0){
hasMissile = false;
return;
}
updateNum(a[1], a[2], a[3]);
}
}
public static void main(String[] args) {
Kesuen kesuen = new Kesuen();
kesuen.update();
}
}
import java.util.Random;
public class Kesuen {
int deadNumber = 0;
int qingchang = 0;
int num = 4;
public void update(){
for(int i=0;i<1000000;i++){
xunhuan();
}
System.out.print("你清场了"+qingchang+"次");
System.out.print("你挂了"+deadNumber+"次");
}
public int updateNum(int a,int b, int c){
num = 1;
if(a > 0){
num++;
}
if(b > 0){
num++;
}
if(c > 0){
num++;
}
return num;
}
public void xunhuan(){
int[] a ={18,6,2,1};
boolean isLive = true;
boolean hasMissile = true;
int missile = 16;
boolean qing = false;
while(isLive && hasMissile){
Random random = new Random();
int flag = random.nextInt(num);
a[flag] = a[flag] - 1;
missile--;
if(a[0] == 0){
deadNumber++;
isLive = false;
return;
}
if(!qing){
if(a[1] == 0&&a[2]!=0){
a[1] = a[2];
a[2] = a[3];
a[3] = 0;
}else if(a[1] == 0&&a[2]==0){
qingchang++;
qing = true;
}
if(a[2] == 0 ){
a[2] = a[3];
a[3] = 0;
}
}
if(missile == 0){
hasMissile = false;
return;
}
updateNum(a[1], a[2], a[3]);
}
}
public static void main(String[] args) {
Kesuen kesuen = new Kesuen();
kesuen.update();
}
}