結果

問題 No.108 トリプルカードコンプ
ユーザー akakimidoriakakimidori
提出日時 2017-06-04 00:09:46
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,403 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 24,624 KB
実行使用メモリ 8,484 KB
最終ジャッジ日時 2023-10-22 03:10:10
合計ジャッジ時間 892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 0 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 4 ms
8,484 KB
testcase_08 AC 0 ms
4,348 KB
testcase_09 AC 0 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 0 ms
4,348 KB
testcase_12 AC 0 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 0 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 3 ms
7,120 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:25:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:31:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%d",&a);
      |     ^~~~~~~~~~~~~~
main.c: In function ‘run2’:
main.c:44:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:50:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |     scanf("%d",&a);
      |     ^~~~~~~~~~~~~~

ソースコード

diff #

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

#define POS(i,j,k) (((i)*(n+1)+(j))*(n+1)+(k)) 

double calc(double *e,int n,int i,int j,int k){
  if(i==0 && j==0 && k==0) return 0.0;
  if(e[POS(i,j,k)]>=1.0) return e[POS(i,j,k)];

  double t=1.0;
  if(i>0) t+=(double)i/n*calc(e,n,i-1,j+1,k);

  if(j>0) t+=(double)j/n*calc(e,n,i,j-1,k+1);

  if(k>0) t+=(double)k/n*calc(e,n,i,j,k-1);

  t/=1-(double)(n-i-j-k)/n;

  e[POS(i,j,k)]=t;
  return t;
}

void run(void){
  int n;
  scanf("%d",&n);

  int cnt[4]={0};
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    cnt[a>=3?3:a]++;
  }
  double *e=(double *)calloc((n+1)*(n+1)*(n+1),sizeof(double));
  calc(e,n,cnt[0],cnt[1],cnt[2]);

  printf("%.6lf\n",e[POS(cnt[0],cnt[1],cnt[2])]);
  free(e);
  return;
}

void run2(void){
  int n;
  scanf("%d",&n);

  int cnt[4]={0};
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    cnt[a>=3?3:a]++;
  }
  double *e=(double *)malloc((n+1)*(n+1)*(n+1)*sizeof(double));
  e[POS(0,0,0)]=0.0;

  double p=(double)1/n;
  int j,k;
  for(i=0;i<=cnt[0];i++){
    for(j=0;j<=cnt[1]+cnt[0]-i;j++){
      for(k=(i==0&&j==0);k<=cnt[2]+cnt[1]+cnt[0]-i-j;k++){
	e[POS(i,j,k)]=(1.0+i*p*(i>0?e[POS(i-1,j+1,k)]:0)+j*p*(j>0?e[POS(i,j-1,k+1)]:0)+k*p*(k>0?e[POS(i,j,k-1)]:0))*n/(i+j+k);
      }
    }
  }

  printf("%.6lf\n",e[POS(cnt[0],cnt[1],cnt[2])]);
  free(e);
  return;
}

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