zoukankan      html  css  js  c++  java
  • 给你出道题---如何蒙题

    人生处处都是选择,考试也是这样。
    不论是单选题、多选题、还是判断题,最终都可以归结为单选题。因为对了就是全对,错了就是全错,不存在对一部分的情况。
    判断题可以看做选项只有2个的单选题,多选题比如选项有N个,可以看做2的N幂个选项的单选题。

    现在有N道单选题,每道题有a[N]种选择,问:

    • 最少期望尝试多少次,才能得到正确答案,使期望次数尽量少的决策树是怎样的?
    • 求一个决策,这个决策在最坏情况下的尝试次数最少

    每次尝试可以给出一个答案列表,然后交卷之后会进行判卷。
    判卷结果有N种情况,表示此次提交的得分情况。

    var courseId=34
    var url = "https://study.bytedance.net/exam/submit"
    var script = document.createElement("script")
    script.src = "https://cdn.bootcss.com/axios/0.18.0/axios.min.js"
    document.body.appendChild(script)
    var items = document.querySelectorAll(".ant-form-item")
    var questions = {}
    for (var i = 0; i < items.length; i++) {
        var item = items[i]
        var label = item.querySelector(".ant-form-item-label")
        if (!label) continue
        var qid = parseInt(label.querySelector("label").getAttribute("for"))
        var mul = item.querySelectorAll(".ant-checkbox-group-item").length
        var single = item.querySelectorAll(".radio-wrapper").length
        questions[qid] = { single: single, mul: mul }
    }
    console.log(questions)
    var qidList = []
    var nowAns = []
    var bestScore=0
    for (var i in questions) {
        qidList.push(parseInt(i))
        if(questions[i].single){
            nowAns.push({ qid: parseInt(i), answer: [0] })
        }else{
            nowAns.push({ qid: parseInt(i), answer: [] })
        }
        
    }
    function submit(ind,nowAns,which){ 
        axios.post(url, { answerList: nowAns,courseId:courseId }).then(function (resp) {
            var score = parseInt(resp.data.score)
            console.log("score "+score)
            if (score >bestScore) {
                bestScore=score
                go(ind + 1, nowAns, 0)
                console.log(ind+" solved ")
            } else {
                go(ind, nowAns, which + 1)
            }
        })
    }
    function toList(which,ansCount){
        var ans=[]
        for(var i=0;i<ansCount;i++){
            if(which&(1<<i)){
                ans.push(i+1)
            }
        }
        return ans
    }
    function go(ind, nowAns, which) {
        console.log(ind+" "+which)
        if (ind >= qidList.length) {
            console.log("做完了")
            showAns()
            return
        }
        var qid = qidList[ind]
        if (questions[qid].single) {
            if(which>=questions[qid].single){
                console.log("impossible "+which)
                return
            }
            nowAns[ind] = { qid: qid, answer: [which + 1] }
            submit(ind,nowAns,which)
        } else {
            if(which>=Math.pow(2,questions[qid].mul)){
                console.log("impossible "+which)
                return
            }
            nowAns[ind] = { qid: qid, answer: toList(which,questions[qid].mul) }
            submit(ind,nowAns,which)
        }
    }
    function showAns(){
        for(var i=0;i<nowAns.length;i++){
            console.log(i+" "+nowAns[i].answer)
        }
    }
    go(0, nowAns, 0)
    
    
  • 相关阅读:
    mysql_fetch_row()获取显示数据
    数组上下移动
    croppie 在Angular8 中使用
    关于 element 的 backToTop
    苹果手机new Date()问题
    js精简代码集合
    vue 中使用高德地图, 地图选点
    代替if else 的表单验证方法!
    记一次webpack打包样式加载问题
    echarts 饼图的指示线(labelline) 问题
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/9251070.html
Copyright © 2011-2022 走看看