結果

問題 No.1009 面積の求め方
ユーザー bal4ubal4u
提出日時 2020-03-21 11:28:58
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 29,516 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 08:33:19
合計ジャッジ時間 1,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yuki 1009 面積の求め方
// 2020.3.21 bal4u

#include <stdio.h>
#include <math.h>

#define DIV       500

int a, b;

// 関数値計算に必要な係数をグローバル変数で渡す
double f(double x) { return (x-a)*(x-b); }

// xmin ~ xmax という空間で積分。細かさは DIV で指定
double integral(void) {
	int i;
	double h, h2, x, ans;
	h = (double)(b-a)/DIV, h2 = 0.5*h, x = a;
	ans = 0, i = DIV; while (i--) ans += f(x) + 4*f(x+h2) + f(x+h), x += h;
	return ans*h/6;
}

int main()
{
	scanf("%d%d", &a, &b);
	if (a == b) puts("0");
	else printf("%.8lf\n", fabs(integral()));
	return 0;
}
0