結果

問題 No.132 点と平面との距離
ユーザー HaarHaar
提出日時 2016-06-09 20:54:34
言語 Haskell
(9.8.2)
結果
AC  
実行時間 2,030 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 4,676 ms
コンパイル使用メモリ 171,904 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-17 12:35:01
合計ジャッジ時間 7,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
7,168 KB
testcase_01 AC 437 ms
8,192 KB
testcase_02 AC 2,030 ms
8,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:17:1: warning: [GHC-94817] [-Wtabs]
    Tab character found here, and in six further locations.
    Suggested fix: Please use spaces instead.
   |
17 |         getLine
   | ^^^^^^^^
[2 of 2] Linking a.out

ソースコード

diff #

data Vector3D = Vector3D{x :: Double, y :: Double, z :: Double}deriving Show
data Plane = Plane{norm :: Vector3D, point::Vector3D} deriving Show

vcross :: Vector3D -> Vector3D -> Vector3D
vcross (Vector3D ax ay az) (Vector3D bx by bz) = Vector3D (ay*bz-az*by) (az*bx-ax*bz) (ax*by-ay*bx)

vadd :: Vector3D -> Vector3D -> Vector3D
vadd (Vector3D ax ay az) (Vector3D bx by bz) = Vector3D (ax+bx) (ay+by) (az+bz)

vinv :: Vector3D -> Vector3D
vinv (Vector3D x y z) = Vector3D (-x) (-y) (-z)

vsub :: Vector3D -> Vector3D -> Vector3D
vsub a b = vadd a (vinv b)

main = do
	getLine
	p <- return . (\(x:y:z:_) -> Vector3D x y z) . map read . words =<< getLine
	q <- return . map ((\(x:y:z:_) -> Vector3D x y z) . map read . words) . lines =<< getContents
	
	let pl = [Plane (vcross (vsub (q!!i) (q!!j)) (vsub (q!!k) (q!!j))) (q!!i) | i<-[0..length q-1], j<-[i+1..length q-1], k<-[j+1..length q-1]]
	
	print $ sum $ map (\(Plane (Vector3D a b c) (Vector3D d e f)) -> abs (a*(x p) + b*(y p) + c*(z p) - a*d - b*e - c*f) / sqrt(a*a+b*b+c*c) ) pl
0