結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-19 02:30:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 504 ms / 3,000 ms |
| コード長 | 1,430 bytes |
| コンパイル時間 | 2,412 ms |
| コンパイル使用メモリ | 77,652 KB |
| 実行使用メモリ | 58,956 KB |
| 最終ジャッジ日時 | 2024-10-04 00:42:32 |
| 合計ジャッジ時間 | 6,433 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
new Main().run();
}
Random rnd=new Random();
boolean f(int[] A,int[] B,double PA,double PB) {
int N=A.length;
int sum=0;
boolean[] a_used=new boolean[N];
boolean[] b_used=new boolean[N];
for (int i=0;i<N;++i) {
double pa=rnd.nextDouble();
double pb=rnd.nextDouble();
int u=0,v=0;
while (a_used[u]) ++u;
while (b_used[v]) ++v;
if (pa>PA && i!=N-1) {
int k=1+rnd.nextInt(N-1-i);//1...,N-i
while (k!=0) {
++u;
if (!a_used[u]) --k;
}
}
if (pb>PB && i!=N-1) {
int k=1+rnd.nextInt(N-1-i);
while (k!=0) {
++v;
if (!b_used[v]) --k;
}
}
if (A[u]>B[v]) {
sum+=A[u]+B[v];
} else {
sum-=A[u]+B[v];
}
a_used[u]=true;
b_used[v]=true;
}
return sum>0;
}
void run() {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
double PA=sc.nextDouble();
double PB=sc.nextDouble();
int[] A=new int[N];
int[] B=new int[N];
for (int i=0;i<N;++i) {
A[i]=sc.nextInt();
}
for (int i=0;i<N;++i) {
B[i]=sc.nextInt();
}
Arrays.sort(A);
Arrays.sort(B);
int T=100000;
int wins=0;
for (int t=0;t<T;++t) {
if (f(A,B,PA,PB)) {
++wins;
}
}
System.out.println(1d*wins/T);
}
void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}