結果

問題 No.133 カードゲーム
ユーザー Kenta NakajimaKenta Nakajima
提出日時 2019-11-26 21:48:12
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,337 bytes
コンパイル時間 1,183 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 16:16:27
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define BUF_SIZE 20


int get_int(char *line, int size) {
  if(!fgets(line, size, stdin)) return 0;
  int num;
  sscanf(line, "%d", &num);
  return num;
}

void fget_array(char *line, int bufsize, int *arr, int size) {
  char *tmpbuf = line;
  int i;
  if(!fgets(line, bufsize, stdin)) return;
  for(i = 0; i < size; i++) {
    char *tmp = strtok(tmpbuf, " ");
    arr[i] = strtol(tmp, NULL, 10);
    tmpbuf = NULL;
  }
  return;
}

int cnt = 0;

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void iterate(int *arr, int n, int start, int end, int *brr) {
  if(start+1 >= end) {
    int i;
    int win = 0;
    for(i = 0; i < n; i++) {
      win += arr[i] > brr[i];
    }
    if(win > n/2) cnt++;
    return;
  }

  int i;
  for(i = start; i < end; i++) {
    swap(&arr[start], &arr[i]);
    iterate(arr, n, start+1, end, brr);
    swap(&arr[start], &arr[i]);
  }
}

int main(void) {
  char line[BUF_SIZE];
  int n = get_int(line, BUF_SIZE);
  int sum = 1;
  int i;
  for(i = 2; i <= n; i++) sum *= i;

  int *arr = (int*)malloc(sizeof(int)*n);
  int *brr = (int*)malloc(sizeof(int)*n);
  fget_array(line, BUF_SIZE, arr, n);
  fget_array(line, BUF_SIZE, brr, n);

  iterate(arr, n, 0, n, brr);
  printf("%lf\n", (double)cnt / (double)sum);
  return 0;
}
0