結果

問題 No.347 微分と積分
ユーザー @abcde
提出日時 2019-04-21 00:06:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 901 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 159,972 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 10:44:53
合計ジャッジ時間 2,018 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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