結果
問題 | No.173 カードゲーム(Medium) |
ユーザー | uwi |
提出日時 | 2015-03-26 23:38:43 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,287 ms / 3,000 ms |
コード長 | 4,600 bytes |
コンパイル時間 | 3,397 ms |
コンパイル使用メモリ | 82,456 KB |
実行使用メモリ | 47,856 KB |
最終ジャッジ日時 | 2024-06-29 01:08:12 |
合計ジャッジ時間 | 16,873 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 183 ms
45,048 KB |
testcase_01 | AC | 323 ms
46,460 KB |
testcase_02 | AC | 1,985 ms
47,208 KB |
testcase_03 | AC | 1,872 ms
47,348 KB |
testcase_04 | AC | 1,754 ms
47,492 KB |
testcase_05 | AC | 1,524 ms
47,568 KB |
testcase_06 | AC | 1,078 ms
47,576 KB |
testcase_07 | AC | 873 ms
47,856 KB |
testcase_08 | AC | 898 ms
47,668 KB |
testcase_09 | AC | 2,287 ms
46,216 KB |
ソースコード
package q4xx; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Random; public class Q325 { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); double pa = nd(), pb = nd(); int[] a = na(n); int[] b = na(n); Arrays.sort(a); Arrays.sort(b); Random gen = new XorShift(); int win = 0; int REP = 1000000; for(int rep = 0;rep < REP;rep++){ boolean[] seda = new boolean[n]; boolean[] sedb = new boolean[n]; int score = 0; for(int i = 0;i < n;i++){ int ah = -1; double ap = gen.nextDouble(); if(i == n-1 || ap < pa){ for(int j = 0;j < n;j++){ if(!seda[j]){ ah = j; break; } } }else{ int ind = gen.nextInt(n-i-1)+1; for(int j = 0;j < n;j++){ if(!seda[j]){ if(--ind < 0){ ah = j; break; } } } } int bh = -1; double bp = gen.nextDouble(); if(i == n-1 || bp < pb){ for(int j = 0;j < n;j++){ if(!sedb[j]){ bh = j; break; } } }else{ int ind = gen.nextInt(n-i-1)+1; for(int j = 0;j < n;j++){ if(!sedb[j]){ if(--ind < 0){ bh = j; break; } } } } if(a[ah] > b[bh]){ score += a[ah] + b[bh]; }else{ score -= a[ah] + b[bh]; } seda[ah] = true; sedb[bh] = true; } if(score > 0){ win++; } } out.printf("%.12f\n", (double)win/REP); } public static class XorShift extends Random { private static final long serialVersionUID = 6806629989739663134L; private long x=123456789, y=362436069, z=521288629, w=88675123; public XorShift() {super(); x = System.nanoTime();} public XorShift(long seed) {super(seed); x = seed;} public synchronized void setSeed(long seed) {super.setSeed(seed); x = seed;} protected int next(int bits){ long t=(x^x<<11)&(1L<<32)-1; x=y; y=z; z=w; w=(w^w>>>19^t^t>>>8)&(1L<<32)-1; return (int)w>>>32-bits; } } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Q325().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }