{"id":106,"date":"2025-10-11T22:23:40","date_gmt":"2025-10-11T14:23:40","guid":{"rendered":"https:\/\/xwyer.lykns.cn\/?p=106"},"modified":"2026-10-13T13:58:33","modified_gmt":"2026-10-13T05:58:33","slug":"%e7%be%a4%e6%98%9f%e8%88%b0%e9%98%9f%e5%ae%9e%e5%8a%9b%e6%9c%80%e5%a4%a7%e5%80%bc%e8%ae%a1%e7%ae%97%e5%99%a8","status":"publish","type":"post","link":"https:\/\/xwyer.lykns.cn\/?p=106","title":{"rendered":"\u7fa4\u661f\u8230\u961f\u5b9e\u529b\u6700\u5927\u503c\u8ba1\u7b97\u5668"},"content":{"rendered":"\n<style data-wp-block-html=\"css\">\n\/* LYKNS Fleet Calculator Styles - WP Theme Compatible *\/\n.lykns-fleet-calc {\n    background: var(--wp--preset--color--background, #f8f9fa);\n    border: 1px solid var(--wp--preset--color--gray-300, #dee2e6);\n    border-radius: var(--wp--style--border-radius, 8px);\n    padding: 1.5rem;\n    margin: 1.5rem 0;\n    font-family: inherit;\n}\n\n.lykns-fleet-calc .lykns-row {\n    display: flex;\n    align-items: center;\n    gap: 0.75rem;\n    margin-bottom: 0.75rem;\n    flex-wrap: wrap;\n}\n\n.lykns-fleet-calc label {\n    min-width: 80px;\n    font-weight: 600;\n    margin: 0;\n}\n\n.lykns-fleet-calc input[type=\"number\"] {\n    width: 100px;\n    padding: 0.4rem 0.6rem;\n    border: 1px solid var(--wp--preset--color--gray-400, #ced4da);\n    border-radius: var(--wp--style--border-radius, 4px);\n    background: var(--wp--preset--color--white, #fff);\n    color: inherit;\n    font-size: inherit;\n}\n\n.lykns-fleet-calc .lykns-unit-label {\n    font-size: 0.875em;\n    opacity: 0.8;\n    white-space: nowrap;\n}\n\n.lykns-fleet-calc .lykns-btn-group {\n    display: flex;\n    gap: 0.5rem;\n    margin-top: 1rem;\n    flex-wrap: wrap;\n}\n\n.lykns-fleet-calc button {\n    padding: 0.45rem 1rem;\n    border: none;\n    border-radius: var(--wp--style--border-radius, 4px);\n    cursor: pointer;\n    font-size: 0.875rem;\n    font-weight: 600;\n    transition: opacity 0.2s;\n}\n\n.lykns-fleet-calc button:hover { opacity: 0.85; }\n\n.lykns-fleet-calc .lykns-btn-add {\n    background: var(--wp--preset--color--primary, #0073aa);\n    color: #fff;\n}\n\n.lykns-fleet-calc .lykns-btn-solve {\n    background: var(--wp--preset--color--vivid-green-cyan, #00a32a);\n    color: #fff;\n}\n\n.lykns-fleet-calc .lykns-btn-del {\n    background: var(--wp--preset--color--vivid-red, #cf2e2e);\n    color: #fff;\n    padding: 0.3rem 0.7rem;\n    font-size: 0.8rem;\n}\n\n.lykns-fleet-calc .lykns-result {\n    margin-top: 1.25rem;\n    padding: 1rem;\n    background: var(--wp--preset--color--white, #fff);\n    border: 1px dashed var(--wp--preset--color--gray-400, #ced4da);\n    border-radius: var(--wp--style--border-radius, 4px);\n    line-height: 1.8;\n}\n\n.lykns-fleet-calc .lykns-mono {\n    font-family: Consolas, Monaco, \"Courier New\", monospace;\n    background: var(--wp--preset--color--gray-100, #eef1f5);\n    padding: 1px 5px;\n    border-radius: 3px;\n    font-weight: 700;\n}\n\n@media (max-width: 600px) {\n    .lykns-fleet-calc .lykns-row { gap: 0.4rem; }\n    .lykns-fleet-calc input[type=\"number\"] { width: 80px; }\n    .lykns-fleet-calc label { min-width: 60px; font-size: 0.9em; }\n}\n<\/style>\n\n<script data-wp-block-html=\"js\">\n<script>\n(function(){\n    \/\/ \u6570\u636e\u6a21\u578b\n    let vars = [\n        { name: 'a', coefObj: 1300, coefConstraint: 2 },\n        { name: 'b', coefObj: 2100, coefConstraint: 8 },\n        { name: 'c', coefObj: 6700, coefConstraint: 16 }\n    ];\n\n    \/\/ \u5355\u7eaf\u5f62\u6cd5\uff08\u5b9e\u6570\u4e0a\u754c\uff09\n    function simplex(c, A, b) {\n        const m = A.length, n = A[0].length;\n        let tbl = [], base = [];\n        for (let i = 0; i < m; i++) {\n            base.push(n + i);\n            tbl.push(A[i].concat(Array(m).fill(0)));\n            tbl[i][n + i] = 1;\n            tbl[i].push(b[i]);\n        }\n        let obj = c.concat(Array(m + 1).fill(0));\n        tbl.push(obj);\n\n        function pivot(r, col) {\n            let pr = tbl[r], p = pr[col];\n            for (let j = 0; j < pr.length; j++) pr[j] \/= p;\n            for (let i = 0; i < tbl.length; i++) {\n                if (i === r) continue;\n                let row = tbl[i], f = row[col];\n                for (let j = 0; j < row.length; j++) row[j] -= f * pr[j];\n            }\n        }\n\n        while (true) {\n            let pivotCol = -1;\n            for (let j = 0; j < n; j++) {\n                if (tbl[tbl.length - 1][j] > 1e-10) { pivotCol = j; break; }\n            }\n            if (pivotCol === -1) break;\n\n            let pivotRow = -1, theta = Infinity;\n            for (let i = 0; i < m; i++) {\n                if (tbl[i][pivotCol] <= 1e-10) continue;\n                let q = tbl[i][tbl[i].length - 1] \/ tbl[i][pivotCol];\n                if (q < theta) { theta = q; pivotRow = i; }\n            }\n            if (pivotRow === -1) return null;\n            pivot(pivotRow, pivotCol);\n            base[pivotRow] = pivotCol;\n        }\n\n        let x = Array(n).fill(0);\n        for (let i = 0; i < m; i++) {\n            if (base[i] < n) x[base[i]] = tbl[i][tbl[i].length - 1];\n        }\n        return { max: -tbl[tbl.length - 1][tbl[0].length - 1], x: x };\n    }\n\n    \/\/ \u6574\u6570\u5206\u652f\u5b9a\u754c\n    function findBestInt(c, A, b, R) {\n        const real = simplex(c, A, b);\n        if (!real) return null;\n        const n = c.length;\n        let bestMax = -Infinity, bestX = null;\n\n        function dfs(depth, curX, curSum, curVal) {\n            if (depth === n) {\n                if (curSum <= R &#038;&#038; curVal > bestMax) {\n                    bestMax = curVal;\n                    bestX = [...curX];\n                }\n                return;\n            }\n            const left = R - curSum;\n            const maxV = Math.floor(left \/ A[0][depth]);\n            if (curVal + maxV * c[depth] <= bestMax) return;\n            for (let v = 0; v <= maxV; v++) {\n                curX[depth] = v;\n                dfs(depth + 1, curX, curSum + v * A[0][depth], curVal + v * c[depth]);\n                curX[depth] = 0;\n            }\n        }\n\n        dfs(0, Array(n).fill(0), 0, 0);\n        return bestX ? { max: bestMax, x: bestX } : null;\n    }\n\n    \/\/ \u6e32\u67d3\n    function render() {\n        const d = document.getElementById('lykns-vars');\n        if (!d) return;\n        d.innerHTML = '';\n        vars.forEach(function(v, idx) {\n            const row = document.createElement('div');\n            row.className = 'lykns-row';\n            row.innerHTML =\n                '<label>\u578b\u53f7 ' + v.name + '<\/label>' +\n                '<input type=\"number\" value=\"' + v.coefObj + '\" step=\"1\" min=\"0\" data-idx=\"' + idx + '\" data-field=\"coefObj\">' +\n                '<span class=\"lykns-unit-label\">\u6218\u529b<\/span>' +\n                '<input type=\"number\" value=\"' + v.coefConstraint + '\" step=\"1\" min=\"0\" data-idx=\"' + idx + '\" data-field=\"coefConstraint\">' +\n                '<span class=\"lykns-unit-label\">\u89c4\u6a21<\/span>' +\n                '<button class=\"lykns-btn-del\" onclick=\"lyknsDelVar(' + idx + ')\">\u5220\u9664<\/button>';\n            d.appendChild(row);\n        });\n\n        \/\/ \u7ed1\u5b9a input \u4e8b\u4ef6\uff08\u66ff\u4ee3\u5185\u8054 onchange\uff0c\u66f4\u53ef\u9760\uff09\n        d.querySelectorAll('input').forEach(function(inp) {\n            inp.addEventListener('change', function() {\n                const i = parseInt(this.dataset.idx);\n                const f = this.dataset.field;\n                vars[i][f] = parseInt(this.value) || 0;\n            });\n        });\n    }\n\n    \/\/ \u66b4\u9732\u5230\u5168\u5c40\n    window.lyknsAddVar = function() {\n        const name = String.fromCharCode(97 + vars.length);\n        vars.push({ name: name, coefObj: 100, coefConstraint: 1 });\n        render();\n    };\n\n    window.lyknsDelVar = function(i) {\n        vars.splice(i, 1);\n        render();\n    };\n\n    window.lyknsSolve = function() {\n        const R = parseInt(document.getElementById('lykns-R').value) || 0;\n        const c = vars.map(function(v) { return v.coefObj; });\n        const A = [vars.map(function(v) { return v.coefConstraint; })];\n        const b = [R];\n        const res = findBestInt(c, A, b, R);\n        const el = document.getElementById('lykns-result');\n\n        if (!res) {\n            el.innerHTML = '\u65e0\u6ee1\u8db3\u6761\u4ef6\u7684\u975e\u8d1f\u6574\u6570\u89e3';\n            return;\n        }\n\n        let html = '\u6700\u5927\u6218\u529b = <span class=\"lykns-mono\">' + res.max + '<\/span><br>';\n        vars.forEach(function(v, i) {\n            html += v.name + ' = <span class=\"lykns-mono\">' + res.x[i] + '<\/span><br>';\n        });\n        const used = res.x.reduce(function(s, x, i) { return s + x * vars[i].coefConstraint; }, 0);\n        html += '\u5df2\u7528\u89c4\u6a21\uff1a<span class=\"lykns-mono\">' + used + '<\/span> \/ ' + R;\n        el.innerHTML = html;\n    };\n\n    \/\/ \u521d\u59cb\u5316\n    if (document.readyState === 'loading') {\n        document.addEventListener('DOMContentLoaded', render);\n    } else {\n        render();\n    }\n})();\n<\/script>\n<\/script>\n\n<div class=\"lykns-fleet-calc\" id=\"lyknsFleetCalc\">\n    <div class=\"lykns-row\">\n        <label for=\"lykns-R\">\u6307\u6325\u4e0a\u9650<\/label>\n        <input id=\"lykns-R\" type=\"number\" value=\"130\" min=\"0\" step=\"1\">\n    <\/div>\n\n    <div id=\"lykns-vars\"><\/div>\n\n    <div class=\"lykns-btn-group\">\n        <button class=\"lykns-btn-add\" onclick=\"lyknsAddVar()\">+ \u589e\u52a0\u578b\u53f7<\/button>\n        <button class=\"lykns-btn-solve\" onclick=\"lyknsSolve()\">\u8ba1\u7b97\u8230\u961f\u5b9e\u529b\u6700\u5927\u503c<\/button>\n    <\/div>\n\n    <h5 style=\"margin-top:1.25rem;margin-bottom:0;\">\u7ed3\u679c<\/h5>\n    <div id=\"lykns-result\" class=\"lykns-result\">\u8bf7\u70b9\u51fb\u201c\u8ba1\u7b97\u8230\u961f\u5b9e\u529b\u6700\u5927\u503c\u201d<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6307\u6325\u4e0a\u9650 + \u589e\u52a0\u578b\u53f7 \u8ba1\u7b97\u8230\u961f\u5b9e\u529b\u6700\u5927\u503c \u7ed3\u679c \u8bf7\u70b9\u51fb\u201c\u8ba1\u7b97\u8230\u961f\u5b9e\u529b\u6700\u5927\u503c\u201d<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_ppma_block_editor_authors":""},"categories":[5],"tags":[],"ppma_author":[7],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-tools","author-captb"],"authors":[{"term_id":7,"user_id":1,"is_guest":0,"slug":"captb","display_name":"CaptB","avatar_url":{"url":"https:\/\/xwyer.lykns.cn\/wp-content\/uploads\/2026\/10\/CaptB.png","url2x":"https:\/\/xwyer.lykns.cn\/wp-content\/uploads\/2026\/10\/CaptB.png"},"avatar_alt":"","avatar_decorative":"","author_category":"1","first_name":"","last_name":"","user_url":"https:\/\/www.lykns.cn\/people\/captb\/","job_title":"LYKNS \u4e3b\u5e2d\u3001\u7ba1\u7406\u7ec4\u53ca\u8fd0\u8425\u7ec4\u6210\u5458","description":"<p>1966 \u5e74\u30012006 \u5e74\u4e24\u5ea6\u8363\u81ba\u300a\u65f6\u4ee3\u5468\u520a\u300b\u5e74\u5ea6\u98ce\u4e91\u4eba\u7269\uff1b2008 \u5e74\u83b7\u8bc4\u300a\u611f\u52a8\u4e2d\u56fd\u300b\u5e74\u5ea6\u4eba\u7269\uff1b2019 \u5e74\u83b7\u8054\u5408\u56fd\u201c\u5730\u7403\u536b\u58eb\u5956\u201d\u8054\u5408\u5956\uff1b2020 \u5e74\u83b7\u300a\u611f\u52a8\u4e2d\u56fd\u300b\u7279\u522b\u81f4\u656c\uff1b2022 \u5e74\u4e0e\u56e2\u961f\u5171\u83b7\u56fd\u9645\u5965\u59d4\u4f1a\u201c\u5965\u6797\u5339\u514b\u5956\u676f\u201d\u3002<\/p>"}],"_links":{"self":[{"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=106"}],"version-history":[{"count":1,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":107,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions\/107"}],"wp:attachment":[{"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=106"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/xwyer.lykns.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fppma_author&post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}