結果

問題 No.347 微分と積分
ユーザー horiesiniti
提出日時 2016-07-21 10:17:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 382 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 61,164 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 20:15:09
合計ジャッジ時間 2,054 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d %lf",&x,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |                 scanf("%lf",&a);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <math.h>
#include <vector>
#include <stdio.h>
using namespace std;

int main() {
	// your code goes here
	int x;
	double b,ans1=0,ans2=0;
	scanf("%d %lf",&x,&b);
	for(int i=0;i<x;i++){
		double a;
		scanf("%lf",&a);
		ans1+=(a*pow(b,a-1));
		if(a!=-1){
			ans2+=(1.0/(a+1)*pow(b,a+1));
		}else{
			ans2+=log(b);
		}
	}
	printf("%lf\n%lf\n",ans1,ans2);
}
0