1的左右必须为2才能乘积为偶数。模拟即可,只用考虑2比1多或者1比2多一个的时候,一直1、2、1、2... 模拟下去
let [a, b] = readline().split(' ').map(Number) // a个1, b个2, 1的左右必须是2 let ans = new Array(a+b).fill(2); if(b >= a || a === b + 1) { for(let i = 0; i < 2 * Math.min(b,a); i+=2) ans[i] = 1 if(a === b+1) ans[ans.length-1] = 1; console.log(ans.join(" ")); } else { console.log(-1); }
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let n, k; rl.on('line', function (line) { let arr = line.split(' ').map(Number); if(arr.length === 2) [n, k] = arr; if(arr.length === n) { for(let i = 0; i < parseInt(n / k); i++) { //每次删除k个,每次挑选重复的删除 let cnt = k; for(let j = 0; j < n; j++) { if(arr [j] !== -1 && arr.indexOf(arr[j]) !== j) { arr[j] = -1; if(cnt-- === 1) break; } } } let flag = true; for(let j = 0; j < n; j++) if(arr [j] !== -1 && arr.indexOf(arr[j]) !== j) flag = false; if(flag) console.log("Yes"); else console.log("No") } });
let [n, k] = readline().split(' ').map(Number); let arr = readline().split(' ').map(Number); let t1 = [], t2 = []; for(let i = 0; i < k; i++) if(arr[i] > k) t1.push(i); for(let j = k; j < n; j++) if(arr[j] <= k) t2.push(j); let ans = 0; for(let idx = 0; idx < t1.length; idx++) ans += (t2[idx] - t1[idx]); console.log(ans);
class cls { static func() {console.log(true);} } cls.func = function() {console.log(false);} cls.func()
let thenable = { then: function(resolve, reject) { reject(1); } } let p = new Promise((resolve, reject) => { resolve(thenable); }) p.then(val=>{console.log(val), err => {console.log(err+1)}})