对于给定的由 个整数组成的数组 ,我们称其为数独数组,当且仅当其每一个长度为 的连续子数组,都包含 这 个数字。 现在,对于给定的数组,是否存在一种方案,使得其经过重新排序后成为数独数组?如果是,直接输出 ;否则,输出 。注意,您不必给出具体的排序方案。
区块链毕设网qklbishe.com为您提供问题的解答
对于给定的由
个整数组成的数组
,我们称其为数独数组,当且仅当其每一个长度为
的连续子数组,都包含
这
个数字。
现在,对于给定的数组,是否存在一种方案,使得其经过重新排序后成为数独数组?如果是,直接输出
;否则,输出
。注意,您不必给出具体的排序方案。
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here while(line = await readline()){ const count = Number(line) const arr = (await readline()).split(' ').map(item => Number(item)) const n = Math.floor(arr.length / 9) const m = arr.length % 9 const hash = new Map() for (let i = 0; i < arr.length; i++) { const item = arr[i] if (hash.has(item)) { hash.set(item, hash.get(item) + 1) } else { hash.set(item, 1) } } let more = 0 for (let i = 1; i <= 9; i++) { const val = hash.get(i) if ([n, n+1].indexOf(val) < 0) { console.log('NO') return } if (val === n + 1) { more++ } } console.log(more === m ? 'YES' : 'NO') } }()
25:57
EASY
#include <array> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; std::array<int, 9> map{}; for (int i = 0; i < n; ++i) { int num; cin >> num; ++map[num - 1]; } int s = n / 9; for (int& a : map) { if (a < s || a > s + 1) { cout << "NO"; return 0; } } cout << "YES"; }
21:54
以上就是关于问题对于给定的由 个整数组成的数组 ,我们称其为数独数组,当且仅当其每一个长度为 的连续子数组,都包含 这 个数字。
现在,对于给定的数组,是否存在一种方案,使得其经过重新排序后成为数独数组?如果是,直接输出 ;否则,输出 。注意,您不必给出具体的排序方案。的答案
欢迎关注区块链毕设网-
web3一级市场套利打新赚钱空投教程
区块链NFT链游项目方科学家脚本开发培训