結果

問題 No.75 回数の期待値の問題
ユーザー akakimidoriakakimidori
提出日時 2017-06-04 02:49:14
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 321 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 22,792 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 03:11:15
合計ジャッジ時間 2,052 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
4,348 KB
testcase_01 AC 67 ms
4,348 KB
testcase_02 AC 5 ms
4,348 KB
testcase_03 AC 8 ms
4,348 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 9 ms
4,348 KB
testcase_09 AC 10 ms
4,348 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 12 ms
4,348 KB
testcase_12 AC 13 ms
4,348 KB
testcase_13 AC 14 ms
4,348 KB
testcase_14 AC 15 ms
4,348 KB
testcase_15 AC 20 ms
4,348 KB
testcase_16 AC 126 ms
4,348 KB
testcase_17 AC 321 ms
4,348 KB
testcase_18 AC 121 ms
4,348 KB
testcase_19 AC 130 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:6:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |   scanf("%d",&k);
      |   ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

void run(void){
  int k;
  scanf("%d",&k);
  double *now=(double *)malloc(sizeof(double)*(k+1));
  double *next=(double *)malloc(sizeof(double)*(k+1));

  int i,j;
  for(i=0;i<=k;i++){
    now[i]=0;
  }

  now[0]=1;
  double ans=0;
  for(i=1;i<=100000;i++){
    for(j=0;j<=k;j++){
      next[j]=0;
    }
    const double f=(double)1/6;
    for(j=0;j<k;j++){
      int n;
      for(n=1;n<=6;n++){
	next[(j+n>k)?0:(j+n)]+=f*now[j];
      }
    }
    ans+=i*next[k];
    next[k]=0;
    double *swap=now;
    now=next;
    next=swap;
  }
  printf("%lf\n",ans);
  return;
}

int main(void){
  run();
  return 0;
}
0