結果

問題 No.1009 面積の求め方
ユーザー Keisuke KubotaKeisuke Kubota
提出日時 2020-03-20 22:24:43
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 11,038 ms
コンパイル使用メモリ 214,016 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-21 17:10:41
合計ジャッジ時間 11,934 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,328 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,360 KB
testcase_03 AC 1 ms
4,364 KB
testcase_04 AC 1 ms
4,360 KB
testcase_05 AC 1 ms
4,364 KB
testcase_06 AC 1 ms
4,364 KB
testcase_07 AC 1 ms
4,364 KB
testcase_08 AC 1 ms
4,388 KB
testcase_09 AC 1 ms
4,364 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,360 KB
testcase_12 AC 1 ms
4,360 KB
testcase_13 AC 1 ms
4,364 KB
testcase_14 AC 1 ms
4,360 KB
testcase_15 AC 1 ms
4,364 KB
testcase_16 AC 1 ms
4,364 KB
testcase_17 AC 1 ms
4,360 KB
testcase_18 AC 2 ms
4,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
 "fmt"
 "math"
)

// 引数の関数の x1 から x2 までの定積分の値の近似値を台形公式により求めて返す関数
// (エラーチェックなし)
// https://ja.wikipedia.org/wiki/%E5%8F%B0%E5%BD%A2%E5%85%AC%E5%BC%8F
const N_SUBINTERVAL = 4000 // 大きくするほど積分の精度がよくなる
var a,b float64

func integrate(f func(float64) float64, x1, x2 float64) float64 {
 if x1 == x2 {
 return 0
 }

 step := ((x2 - x1) / N_SUBINTERVAL)
 sum := 0.5 * f(x1)
 x := x1
 for i := 1; i < N_SUBINTERVAL; i++ {
 x += step
 sum += f(x)
 }
 sum += 0.5 * f(x2)

 return sum * step
}

// f(x) = 4 * (1-x^2)^(1/2)
func testfunc(x float64) float64 {
 return (x-a) * (x-b)
 return 4 * math.Sqrt(1-math.Pow(x, 2))
}

func main() {
  fmt.Scan(&a)
  fmt.Scan(&b)
 // answer equals pi.
 fmt.Println(math.Abs(integrate(testfunc, a, b)))
}
0