結果

問題 No.173 カードゲーム(Medium)
ユーザー fmhrfmhr
提出日時 2015-05-17 05:42:17
言語 Go1.4
(1.4.2)
結果
AC  
実行時間 2,426 ms / 3,000 ms
コード長 1,708 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 34,516 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 11:54:48
合計ジャッジ時間 17,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
4,384 KB
testcase_01 AC 305 ms
4,384 KB
testcase_02 AC 2,080 ms
4,384 KB
testcase_03 AC 2,073 ms
4,384 KB
testcase_04 AC 2,025 ms
4,380 KB
testcase_05 AC 1,772 ms
4,384 KB
testcase_06 AC 1,618 ms
4,384 KB
testcase_07 AC 1,533 ms
4,380 KB
testcase_08 AC 1,521 ms
4,384 KB
testcase_09 AC 2,426 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math/rand"
	"time"
	"bufio"
	"os"
	"strconv"
	"sort"
)

var s = bufio.NewScanner(os.Stdin)
func next() string {s.Split(bufio.ScanWords); s.Scan(); return s.Text()}
func nextInt() int { i, e := strconv.Atoi(next()); if e != nil { panic(e)}; return int(i)}

func copySlice(a []int) []int{
	b := make([]int, len(a))
	copy(b, a)
	return b
}

func removeSlice(a []int, x int) ([]int) {
	b := append(a[:x], a[x+1:]...)
	return b
}

func popSlice(a []int, x int) ([]int, int) {
	r := a[x]
	b := removeSlice(a, x)
	return b, r
}

func main() {
	var n int
	var pa, pb float64
	fmt.Scan(&n, &pa, &pb)
	a := make([]int, n)
	b := make([]int, n)
	rand.Seed(time.Now().UnixNano())
	for i:=0;i<n;i++{
		a[i] = nextInt()
	}
	for i:=0;i<n;i++{
		b[i] = nextInt()
	}
	sort.Ints(a)
	sort.Ints(b)
	win_a := 0
	win_b := 0
	X := 500000
	for i:=0;i<X;i++{
		score_a := 0
		score_b := 0
		sub_a := copySlice(a)
		sub_b := copySlice(b)
		for j:=0;j<n;j++ {
//			fmt.Println(sub_a)
//			fmt.Println(sub_b)
			ca := 0
			cb := 0
			if j<n-1 {
				if pa > rand.Float64() {
					sub_a, ca = popSlice(sub_a, 0)
				}else {
					sub_a, ca = popSlice(sub_a, rand.Intn(len(sub_a)-1)+1)
				}
				if pb > rand.Float64() {
					sub_b, cb = popSlice(sub_b, 0)
				}else {
					sub_b, cb = popSlice(sub_b, rand.Intn(len(sub_b)-1)+1)
//					cb = sub_b[rand.Intn(len(sub_b)-1)+1]
				}
			}else {
				ca = sub_a[0]
				cb = sub_b[0]
			}
			if ca > cb {
				score_a += ca + cb
			}else {
				score_b += ca + cb
			}
		}
		if score_a > score_b{
//			fmt.Println("a WIN!")
			win_a += 1
		}else{
//			fmt.Println("a LOSE!")
			win_b += 1
		}

	}
//	fmt.Println(win_a, win_b)
	fmt.Println(float64(win_a)/float64(X))

}
0