結果

問題 No.425 ジャンケンの必勝法
ユーザー aru aruaru aru
提出日時 2021-01-05 11:01:49
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,960 bytes
コンパイル時間 16,286 ms
コンパイル使用メモリ 241,796 KB
実行使用メモリ 126,420 KB
最終ジャッジ日時 2024-04-23 17:15:49
合計ジャッジ時間 15,875 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
126,416 KB
testcase_01 AC 126 ms
126,420 KB
testcase_02 AC 163 ms
126,420 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 126 ms
126,416 KB
testcase_16 AC 123 ms
126,420 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 132 ms
126,292 KB
testcase_22 AC 135 ms
126,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func getI() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func rec(n, tgl int, p float64) float64 {
	if n == N {
		return 1
	}
	ret := 0.0
	ret = p/2.0 + (1-p)/3.0
	nextP := 0.0
	if tgl == 0 {
		nextP = math.Min(1.0, p+q)
		tgl = 1
	} else {
		nextP = math.Max(0.0, p-q)
		tgl = 0
	}
	r := rec(n+1, tgl, nextP)
	ret += p*r/2.0 + (1-p)*r/3.0
	return ret
}

var p0, q float64
var N = 1000000

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	p0, q = getF()/100.0, getF()/100.0
	ret := rec(0, 1, p0)/3.0 + 1/3.0
	out(ret)
}
0