{"id":101678,"student_id":1658,"content":"// noprotect\n// 三個等級 level 1 ~ 3\nlevel = 3;\nif (level == 1) {\n var weight = 0;\n var value = 0;\n var bestValue = 0;\n var best = 0;\n for (var i = 0; i \u003c (2**5); i++) {\n var num = i.toString(2);\n var w = 0;\n var v = 0;\n for (var x = 0; x \u003c 5; x++) {\n if (num[x] == '1') {\n w += shells[x].weight;\n v += shells[x].value;\n\n }\n if (w \u003c= 1000 \u0026\u0026 v \u003e bestValue) {\n bestValue = v;\n best = num;\n }\n\n }\n\n }\n for (var a = 0; a \u003c 5; a++) {\n if (best[a] == '1') {\n take(shells[a]);\n }\n }\n\n}\n\nif (level == 2) {\n // var weight = 0;\n // var value = 0;\n var bestValue = 0;\n var best = 0;\n for (var i = 0; i \u003c (2**10); i++) {\n var num = i.toString(2);\n var w = 0;\n var v = 0;\n for (var x = 0; x \u003c 10; x++) {\n if (num[x] == '1') {\n w += shells[x].weight;\n v += shells[x].value;\n\n }\n if (w \u003c= 2000 \u0026\u0026 v \u003e bestValue) {\n bestValue = v;\n best = num;\n }\n\n }\n\n }\n for (var a = 0; a \u003c 10; a++) {\n if (best[a] == '1') {\n take(shells[a]);\n }\n }\n}\n\nif (level == 3) {\n var weight = 0;\n var value = 0;\n var bestValue = 0;\n var best = 0;\n for (var i = 0; i \u003c (2**15); i++) {\n var num = i.toString(2);\n var w = 0;\n var v = 0;\n for (var x = 0; x \u003c 15; x++) {\n if (num[x] == '1') {\n w += shells[x].weight;\n v += shells[x].value;\n\n }\n if (w \u003c= 3000 \u0026\u0026 v \u003e bestValue) {\n bestValue = v;\n best = num;\n }\n\n }\n\n }\n for (var a = 0; a \u003c 15; a++) {\n if (best[a] == '1') {\n take(shells[a]);\n }\n }\n}","created_at":"2019-10-20T10:10:40.976+08:00","updated_at":"2019-10-30T04:15:37.311+08:00","name":"背包問題 副本","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/101678/e5cfa8a43aea0bd43b9c4c0b26bad704.jpg"},"parent_id":34006,"plugin":"setBackdrop(\"#222\");\n\nvar level = 1;\n\nvar env = (function () {\n\n var shells = [\n createSprite('shell_0.png'),\n createSprite('shell_1.png'),\n createSprite('shell_2.png'),\n createSprite('shell_3.png'),\n createSprite('shell_4.png'),\n createSprite('shell_5.png'),\n createSprite('shell_6.png'),\n createSprite('shell_7.png'),\n createSprite('shell_8.png'),\n createSprite('shell_z.png'),\n createSprite('shell_10.png'),\n createSprite('shell_11.png'),\n createSprite('shell_12.png'),\n createSprite('shell_13.png'),\n createSprite('shell_2.png'),\n ];\n \n var bag = [];\n\n var values = [150, 220, 220, 290, 425, 475, 470, 615, 610, 720, 990, 850, 900, 950, 1200];\n var weight = [100, 210, 230, 330, 390, 470, 450, 610, 595, 710, 800, 890, 900, 900, 1250];\n \n var limit = [0, 1000, 2000, 3000];\n\n shells.forEach((s, idx) =\u003e {\n s.scale = 0.3;\n s.opacity = 0.5;\n s.x = 106 + 106*(idx%5);\n s.y = 120 + 120*(Math.floor(idx/5))\n s.value = values[idx];\n s.weight = weight[idx];\n \n s.on('click', function () {\n this.enlarge = true;\n var idx = bag.indexOf(this);\n if (idx != -1) bag.splice(idx, 1);\n else bag.push(this);\n });\n });\n \n forever(function(){\n \n if (level == 1) {\n while (shells.length \u003e 5) shells.pop().destroy();\n }\n else if (level == 2) {\n while (shells.length \u003e 10) shells.pop().destroy();\n }\n else if (level == 3) {\n \n } else {\n level = 1;\n }\n \n shells.forEach(function (s) {\n if(s.touched(cursor)) {\n if (cursor.isDown) s.scale = 0.35;\n else s.scale = 0.3;\n s.opacity = 1;\n print(`價格 ${s.value} 元`, cursor.x - 40, cursor.y + 20, 'white');\n print(`重量 ${s.weight} 公斤`, cursor.x - 40, cursor.y + 40, 'white');\n } else {\n s.opacity = .5;\n }\n });\n \n var w = 0;\n var v = 0;\n bag.forEach(function (s) {\n w += s.weight;\n v += s.value;\n s.opacity = 1;\n });\n print(`上限 ${limit[level]}`, 80, 30, 'white', 25);\n print(`重量: ${w}`, 240, 30, w \u003c limit[level] ? 'white': 'orange', 25);\n print(`價格: ${v}`, 400, 30, 'white', 25);\n });\n \n return {\n shells: shells,\n bag: bag,\n take: bag.push.bind(bag)\n }\n})();\n\nvar shells = env.shells;\nvar take = env.take;\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":104,"hashid":"zpes4men","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":1719845,"file_name":"shell_0.png","project_id":101678,"asset_id":75050,"created_at":"2019-10-20T10:10:40.981+08:00","updated_at":"2019-10-20T10:10:40.981+08:00"},{"id":1719846,"file_name":"shell_5.png","project_id":101678,"asset_id":75049,"created_at":"2019-10-20T10:10:40.982+08:00","updated_at":"2019-10-20T10:10:40.982+08:00"},{"id":1719847,"file_name":"shell_7.png","project_id":101678,"asset_id":75048,"created_at":"2019-10-20T10:10:40.983+08:00","updated_at":"2019-10-20T10:10:40.983+08:00"},{"id":1719848,"file_name":"shell_8.png","project_id":101678,"asset_id":75047,"created_at":"2019-10-20T10:10:40.984+08:00","updated_at":"2019-10-20T10:10:40.984+08:00"},{"id":1719849,"file_name":"shell_z.png","project_id":101678,"asset_id":75046,"created_at":"2019-10-20T10:10:40.985+08:00","updated_at":"2019-10-20T10:10:40.985+08:00"},{"id":1719850,"file_name":"shell_1.png","project_id":101678,"asset_id":75045,"created_at":"2019-10-20T10:10:40.986+08:00","updated_at":"2019-10-20T10:10:40.986+08:00"},{"id":1719851,"file_name":"shell_2.png","project_id":101678,"asset_id":75044,"created_at":"2019-10-20T10:10:40.986+08:00","updated_at":"2019-10-20T10:10:40.986+08:00"},{"id":1719852,"file_name":"shell_4.png","project_id":101678,"asset_id":75043,"created_at":"2019-10-20T10:10:40.987+08:00","updated_at":"2019-10-20T10:10:40.987+08:00"},{"id":1719853,"file_name":"shell_3.png","project_id":101678,"asset_id":75042,"created_at":"2019-10-20T10:10:40.988+08:00","updated_at":"2019-10-20T10:10:40.988+08:00"},{"id":1719854,"file_name":"shell_13.png","project_id":101678,"asset_id":75041,"created_at":"2019-10-20T10:10:40.989+08:00","updated_at":"2019-10-20T10:10:40.989+08:00"},{"id":1719855,"file_name":"shell_6.png","project_id":101678,"asset_id":75040,"created_at":"2019-10-20T10:10:40.990+08:00","updated_at":"2019-10-20T10:10:40.990+08:00"},{"id":1719856,"file_name":"shell_12.png","project_id":101678,"asset_id":75039,"created_at":"2019-10-20T10:10:40.990+08:00","updated_at":"2019-10-20T10:10:40.990+08:00"},{"id":1719857,"file_name":"shell_11.png","project_id":101678,"asset_id":75038,"created_at":"2019-10-20T10:10:40.991+08:00","updated_at":"2019-10-20T10:10:40.991+08:00"},{"id":1719858,"file_name":"shell_10.png","project_id":101678,"asset_id":75037,"created_at":"2019-10-20T10:10:40.992+08:00","updated_at":"2019-10-20T10:10:40.992+08:00"}]
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
繁中
简中
English
日本語
1:1:1
1:1
全寬
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦