DNF装备强化的算法分析与实现
DNF装备强化的算法分析与实现
DNF装备强化的算法分析与实现
需求
根据输⼊的当前等级和⽬标等级,得到强化到⽬标等级所需的强化次数(或装备爆掉),强化规则如下:
DNF装备强化在+1~+3 不会失败;
+4~+7,失败后物品原有强化等级降低1级;
+8~+10,失败后掉3级;
10上11或以上就爆了。
DNF装备强化1~3级,成功率100%
DNF装备强化3~4级,成功率95%
DNF装备强化4~5级,成功率90%
DNF装备强化5~6级,成功率80%
DNF装备强化6~7级,成功率75%
DNF装备强化7~8级,成功率62.1%
DNF装备强化8~9级,成功率53.7%
DNF装备强化9~10级,成功率41.4%
DNF装备强化10~11级,成功率33.9%
DNF装备强化11~12级,成功率28%
DNF装备强化12~13级,成功率20.7%
DNF装备强化13~14级,成功率17.3%
DNF装备强化14~15级,成功率13.6%
DNF装备强化15~16级,成功率10.1%
算法分析
装备的等级可以⽤switch实现,成功概率可以⽤随机数实现,每次强化后判断是否达到⽬标等级,如未达到,则再次强化,直⾄强化到⽬标等级或装备爆掉。因为需多次⽤到强化和等级判断,所以可以将强化和等级判断分别封装成两个⽅法,多次互相调⽤来实现需求。
代码实现
import java.util.Scanner;
public class Dnf {
//计数器
int count =0;
/**
* 判断是否达到⽬标等级,若未达到则继续强化
* @param nowLevel
* @param targetLevel
*/
public void intensify01(int nowLevel,int targetLevel){
if(nowLevel < targetLevel){
intensify(nowLevel,targetLevel);
}else{
System.out.println("强化所⽤次数:"+ count);
return;
}
}
}
/
**
* 强化装备
* @param nowLevel
* @param targetLevel
*/
public void intensify(int nowLevel,int targetLevel){
switch(nowLevel){
case0:
case1:
case2:
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);  count++;
intensify01(nowLevel,targetLevel);
break;
case3:
int n3 =(int)(Math.random()*1000);
if(n3 <950){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case4:
int n4 =(int)(Math.random()*1000);
if(n4 <900){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
nowLevel -=1;
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case5:
int n5 =(int)(Math.random()*1000);
if(n5 <800){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
nowLevel -=1;
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case6:
int n6 =(int)(Math.random()*1000);
if(n6 <750){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
未成年怀孕>火车票几点放票
nowLevel -=1;蒋正寒
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case7:
int n7 =(int)(Math.random()*1000);
if(n7 <621){
if(n7 <621){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
nowLevel -=1;
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case8:
int n8 =(int)(Math.random()*1000);
if(n8 <537){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
nowLevel -=3;
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case9:
int n9 =(int)(Math.random()*1000);
if(n9 <414){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
nowLevel -=3;
System.out.println("强化失败,当前等级:"+ nowLevel);
count++;
}
intensify01(nowLevel,targetLevel);
break;
case10:
int n10 =(int)(Math.random()*1000);
if(n10 <339){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
System.out.println("很遗憾,强化失败,装备损坏!");
count++;
System.out.println("强化所⽤次数:"+ count);
return;
}
intensify01(nowLevel,targetLevel);
break;
case11:
int n11 =(int)(Math.random()*1000);
if(n11 <280){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
System.out.println("很遗憾,强化失败,装备损坏!");
count++;
System.out.println("强化所⽤次数:"+ count);
return;
}
intensify01(nowLevel,targetLevel);
break;
case12:
手机突然连不上家里的wifiint n12 =(int)(Math.random()*1000);
if(n12 <207){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);    count++;
}else{
}else{
System.out.println("很遗憾,强化失败,装备损坏!");nice
count++;
System.out.println("强化所⽤次数:"+ count);
return;
}
intensify01(nowLevel,targetLevel);
break;
case13:
int n13 =(int)(Math.random()*1000);
if(n13 <173){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);
count++;
}else{
System.out.println("很遗憾,强化失败,装备损坏!");
count++;
System.out.println("强化所⽤次数:"+ count);
return;
}
男孩好名字intensify01(nowLevel,targetLevel);
break;
case14:
int n14 =(int)(Math.random()*1000);
if(n14 <136){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);
count++;
}else{
System.out.println("很遗憾,强化失败,装备损坏!");
count++;
System.out.println("强化所⽤次数:"+ count);
return;
}
intensify01(nowLevel,targetLevel);
break;
case15:
int n15 =(int)(Math.random()*1000);
if(n15 <101){
System.out.println("恭喜你强化成功,当前等级:"+++nowLevel);
count++;
}else{
System.out.println("很遗憾,强化失败,装备损坏!");
count++;
System.out.println("强化所⽤次数:"+ count);
return;
}
intensify01(nowLevel,targetLevel);
break;
}
}
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
System.out.print("输⼊当前等级:");
int nowLevel = sc.nextInt();
System.out.print("输⼊⽬标等级:");
int targetLevel = sc.nextInt();
Dnf id =new Dnf();
if(nowLevel >=0&& nowLevel <=16&& targetLevel >=0&& targetLevel <=16){  id.intensify01(nowLevel,targetLevel);
}else{
System.out.println("输⼊的等级⽆效!");
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。