結果
| 問題 |
No.133 カードゲーム
|
| コンテスト | |
| ユーザー |
t8m8⛄️
|
| 提出日時 | 2015-04-09 13:35:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 5,000 ms |
| コード長 | 1,560 bytes |
| コンパイル時間 | 3,514 ms |
| コンパイル使用メモリ | 78,072 KB |
| 実行使用メモリ | 41,976 KB |
| 最終ジャッジ日時 | 2024-06-25 03:29:54 |
| 合計ジャッジ時間 | 7,333 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
//No.133 カードゲーム
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class No133 {
static final Scanner in = new Scanner(System.in);
static final PrintWriter out = new PrintWriter(System.out,false);
static void solve() {
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i=0; i<n; i++) a[i] = in.nextInt();
for (int i=0; i<n; i++) b[i] = in.nextInt();
int win = 0,game = 0;
sort(a);
do {
int cnt = 0;
for (int i=0; i<n; i++) {
if (a[i] - b[i] > 0) cnt++;
}
if (cnt > n/2) win++;
game++;
}while(nextPermutation(a));
out.println((double)win/game);
}
static boolean nextPermutation(int[] a) {
int n = a.length, i, j;
for (i=n-2; i>=0 && a[i]>=a[i+1]; i--);
if (i == -1) return false;
for (j=i+1; j<n && a[i]<a[j]; j++);
int temp = a[i]; a[i] = a[j-1]; a[j-1] = temp;
for (int l=i+1, r=n-1; l<r; l++,r--) {
temp = a[l]; a[l] = a[r]; a[r] = temp;
}
return true;
}
public static void main(String[] args) {
long start = System.currentTimeMillis();
solve();
out.flush();
long end = System.currentTimeMillis();
//trace(end-start + "ms");
in.close();
out.close();
}
static void trace(Object... o) { System.out.println(deepToString(o));}
}
t8m8⛄️