AcWing 1012. 友好城市 (Javascript)
原题链接
简单
作者:
cp777
,
2021-03-10 12:42:17
,
所有人可见
,
阅读 439
const N = 5010;
let g = [];
g.push([0,0]);
let f = new Int32Array(N).fill(1);
let sort = () => {}
let buf = '';
process.stdin.on('readable', function () {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
let getInputNums = line => line.split(' ').filter(s => s !== '').map(x => parseInt(x));
let getInputStr = line => line.split(' ').filter(s => s !== '');
process.stdin.on('end', function () {
buf.split('\n').forEach(function (line, lineIdx) {
if (lineIdx === 0) {
n = getInputNums(line)[0];
} else if (lineIdx <= n) {
let arr = getInputNums(line);
arr.unshift(0);
g.push(arr);
if (lineIdx === n) {
g.sort((a,b) => a[1] - b[1]);
let res = 0;
for (let i = 1; i <= n; i++) {
for (let j = 1; j < i; j++) {
if (g[i][1] > g[j][1] && g[i][2] > g[j][2]) f[i] = Math.max(f[i], f[j] + 1);
}
res = Math.max(res, f[i]);
}
console.log(g);
}
}
});
});