1process.stdin.resume(); 2process.stdin.setEncoding('utf-8'); 3let input = ''; 4 5process.stdin.on('data', (data) => { 6 input += data; 7}); 8 9process.stdin.on('end', () => { 10 const pointsStr = input.trim(); 11 const pointsArray = pointsStr.split(',').map(pointStr => { 12 const [x, y] = pointStr.trim().split(' ').map(Number); 13 return [x, y]; 14 }); 15 16 function triangleArea(p1, p2, p3) { 17 const [x1, y1] = p1; 18 const [x2, y2] = p2; 19 const [x3, y3] = p3; 20 return Math.abs(0.5 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))); 21 } 22 23 let maxArea = 0; 24 const origin = [0, 0]; 25 26 for (let i = 0; i < pointsArray.length; i++) { 27 if (pointsArray[i][0] === 0 && pointsArray[i][1] === 0) continue; // Skip the origin itself 28 for (let j = i + 1; j < pointsArray.length; j++) { 29 if (pointsArray[j][0] === 0 && pointsArray[j][1] === 0) continue; // Skip the origin itself 30 const area = triangleArea(origin, pointsArray[i], pointsArray[j]); 31 if (area > maxArea) { 32 maxArea = area; 33 } 34 } 35 } 36 37 console.log(maxArea.toFixed(2)); 38 process.exit(); 39});
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语