結果

問題 No.1009 面積の求め方
コンテスト
ユーザー bal4u
提出日時 2020-03-21 11:28:58
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 616 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 191 ms
コンパイル使用メモリ 41,316 KB
最終ジャッジ日時 2026-02-22 05:30:11
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// 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