约瑟夫问题

//main
public class Test {
    public static void main(String[] args) {
        System.out.println("please input a num:");
        int a = NumUtil.getInt();
        List go = new ArrayList();
        int b;
        do {
            System.out.println("please input a interval num:");
            b = NumUtil.getInt();
            if (b < a && b != 0) {
                break;
            } else {
                System.out.println("must be littler than last one!");
            }
        } while (true);
        int[] old=new int[a];
        for(int i=0;i<a;i++){
            old[i]=i+1;
        }

        int c=a;
        int k=1;
        do {
            int num=0;
            int length=old.length;
            List teml=new ArrayList();
            for(int j=0;j<length;j++){
                if (k % b == 0) {
                    int temp=old[j];
                    teml.add(temp);
                    go.add(temp);
                    num++;
                }
                k++;
            };
            System.out.println(Arrays.toString(old));
            old=NumUtil.remove(old,teml);
            c-=num;
            if(c==1){
                break;
            }

        } while (true);
        System.out.println(go.toString());
    }
}

工具类

public class NumUtil {
    public static int getInt(){
        Scanner scan=new Scanner(System.in);
        int a;
        try {
             a = scan.nextInt();
        }catch(Exception e){
            System.out.println("格式不正确!");
            a=getInt();
            scan.nextLine();
        }
        return a;
    }
    public static int[] remove(int[] list, List temp){
        int a=0;
        int[] na=new int[list.length-temp.size()];
        for(int i=0;i<list.length;i++){
            boolean flag=true;
            for(int k=0;k<temp.size();k++){
                if(list[i]==(int)temp.get(k)){
                    flag=false;
                    break;
                }
            }
           if(flag){
               na[a]=list[i];
               a++;
           }
        }
        return na;
    }
}

//封装对象--------------------------------------------------------------------===================================-------------------------------------------------------------

public class ChildCyle {
    private Child firstChild;
    private Child temp;
    private int childNum;
    private int  interval;

    public void setChildLink(){
        for(int i=1;i<=childNum;i++){
            if(i==1){
                Child ch=new Child(1);
                this.firstChild=ch;
                this.temp=ch;
            }else if(i==childNum){
                Child ch=new Child(i);
                temp.setNextChild(ch);
                ch.setNextChild(this.firstChild);
            }else{
                Child ch=new Child(i);
                temp.setNextChild(ch);
                this.temp=ch;

            }
        }
    }
    public void play(){
        List go=new ArrayList();
        temp=this.firstChild;
        do{
            for(int i=1;i<this.interval-1;i++){
                temp=temp.getNextChild();
            }
            go.add(temp.getNextChild().getNo());
            temp.setNextChild(temp.getNextChild().getNextChild());
            temp=temp.getNextChild();
        }while(temp!=temp.getNextChild());
        System.out.println(go.toString());
    }
    public void show(){
        temp=this.firstChild;
        do{
            System.out.println(temp.getNo());
            temp=temp.getNextChild();
        }while(temp!=firstChild);
    }
    public void setFirstChild(Child firstChild) {
        this.firstChild = firstChild;
    }
    public void setTemp(Child temp) {
        this.temp = temp;
    }
    public void setChildNum(int childNum) {
        this.childNum = childNum;
    }
    public void setInterval(int interval) {
        this.interval = interval;
    }
}
class Child{
    private int no;
    private Child nextChild;
    public Child(int no){
        this.no=no;
    }
    public void setNo(int no) {
        this.no = no;
    }
    public int getNo(){
        return this.no;
    }
    public Child getNextChild(){
        return this.nextChild;
    }
    public void setNextChild(Child nextChild) {
        this.nextChild = nextChild;
    }
}
class Test{
    public static void main(String[] args) {
        ChildCyle cc=new ChildCyle();
        cc.setChildNum(7);
        cc.setInterval(2);
        cc.setChildLink();
       // cc.show();
        cc.play();
    }
}



内容概要:本文深入研究了基于深度强化学习(DRL)的微网储能系统控制策略。首先介绍了微网系统的组成及其特性,重点探讨了光伏发电、储能系统和负荷系统的关键组件数学模型。接着详细描述了Simulink仿真设计实现,包括微网环境模拟类(MicrogridEnv)、双重深度Q网络(Double DQN)算法的实现以及训练过程。为了验证该方法的有效性,文章还进行了对比实验,分别测试了规则策略、传统优化方法和DDQN策略的表现。实验结果显示,DDQN策略在成本节约、SOC合规率等方面明显优于其他两种方法。最后,本文提出了创新点与贡献总结,包括仿真-学习一体化框架、改进的DRL算法以及多维度验证,并展望了后续研究方向如多时间尺度优化、多能源协同、不确定性处理等。 适用人群:从事电力系统、微网技术研究的专业人士,以及对深度强化学习应用于能源领域感兴趣的科研人员和工程师。 使用场景及目标:①掌握微网储能系统的基本构成与工作原理;②理解如何利用深度强化学习优化微网储能控制策略;③学习具体的算法实现细节,包括环境搭建、DDQN算法实现和训练流程;④对比不同控制策略的效果,评估DDQN策略的优势。 其他说明:本文不仅提供了理论分析和技术实现,还展示了详细的实验验证过程,通过具体的实验数据证明了所提方法的有效性。此外,文中提及的多种改进措施和技术细节对于实际工程项目具有重要的参考价值。阅读本文有助于读者全面了解微网储能控制领域的最新进展,为相关研究和技术开发提供有益的指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值