結果

問題 No.210 探し物はどこですか?
ユーザー autotaker1984
提出日時 2015-04-07 16:52:01
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1,343 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 22,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 10:47:51
合計ジャッジ時間 7,174 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:11:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d",&x);
      |     ^~~~~~~~~~~~~~
main.c:16:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     scanf("%d",&x);
      |     ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

int n;
double p[1001];
double q[1001];
int main(void) {
  int i;
  scanf("%d",&n);
  for( i = 0; i < n; i++ ) {
    int x;
    scanf("%d",&x);
    p[i] = x / 1000.0;
  }
  for( i = 0; i < n; i++ ) {
    int x;
    scanf("%d",&x);
    q[i] = x / 100.0;
  }
  for( i = 0; i < n; i++ )
    p[i] *= q[i];
  double exp = 0;
  double rem = 1.0;
  int c = 1;
  while(1) {
    double mp = p[0];
    int mi = 0;
    for( i = 1; i < n; i++ ) {
      if( mp < p[i] ) {
        mi = i;
        mp = p[i];
      }
    }
    exp += c * mp;
    rem -= mp;
    c++;
    if( rem * (c + exp) < exp * 1e-3 ) {
      exp = exp + rem * (c + exp);
      break;
    }
    p[mi] *= 1 - q[mi];
  }
  printf("%5f\n",exp);
  return 0;
}


0