<!DOCTYPE html>
<html>
<body>
<p>华为OD机试 - 多段线数据压缩(JS 2025 C卷 100分)</p >
<p id="demo"></p >
<script>
/*
var input = [];
let count = 0;
while(line = await readline()){
input[count] = line;
count++;
}
*/
let input = "2 8 3 7 3 6 3 5 4 4 5 3 6 2 7 3 8 4 7 5";
input = input.split(" ").map(Number);
main(input)
function main(input){
let res = input.slice(0, 4);
for(let i = 4; i < input.length; i+=2){
if(check(input[i-4],input[i-3],input[i-2],input[i-1],input[i],input[i+1])){
res.pop();
res.pop();
}
res.push(input[i]);
res.push(input[i+1]);
}
console.log(res.join(" "));
}
function check(x1,y1,x2,y2,x3,y3){
return Math.abs((y3-y1)*(x2-x1)) == Math.abs((y2-y1)*(x3-x1));
}
</script>
</body>
</html>
仅仅过测试用例
&spm=1001.2101.3001.5002&articleId=151157660&d=1&t=3&u=8218c91fe9ad4d1b8d2a8ef5a445885d)
1万+

被折叠的 条评论
为什么被折叠?



