結果

問題 No.173 カードゲーム(Medium)
ユーザー uwiuwi
提出日時 2015-03-26 23:38:15
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 4,600 bytes
コンパイル時間 4,740 ms
コンパイル使用メモリ 86,064 KB
実行使用メモリ 65,292 KB
最終ジャッジ日時 2024-06-29 01:07:13
合計ジャッジ時間 9,396 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
50,444 KB
testcase_01 AC 454 ms
46,380 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = 3000000;
		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)); }
}
0