結果

問題 No.347 微分と積分
ユーザー @abcde@abcde
提出日時 2019-04-21 00:06:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 901 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 160,320 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 08:59:46
合計ジャッジ時間 2,179 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// if文多かったので, 減らした.
#include <bits/stdc++.h>
using namespace std;

int main() {
    
    // 1. 入力情報取得.
    int N, B;
    cin >> N >> B;
    double a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    
    // 2. 微分した値f'(B)の値を計算.
    double differential = 0.0;
    for(int i = 0; i < N; i++){
        if(a[i] == 1.0)                differential += 1.0;
        if(a[i] != 1.0 && a[i] != 0.0) differential += a[i] * pow(B, a[i] - 1.0);
    }
    
    // 3. 積分した値F(B)の値を計算.
    double integration = 0.0;
    for(int i = 0; i < N; i++){
        if(a[i] == -1.0) integration += log(B);
        if(a[i] != -1.0) integration += 1.0 / (a[i] + 1.0) * pow(B, a[i] + 1.0);
    }
    
    // 4. 出力.
    cout << fixed;
    cout << setprecision(10);
    cout << differential << endl;
    cout << integration << endl;
    return 0;
    
}
0