add new solutions

This commit is contained in:
Yiyang Kang 2026-03-01 13:45:00 +09:00
parent ee1868a10e
commit 2012261d3d
7 changed files with 205 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package q762
var isPrime = [21]bool{}
func init() {
for _, n := range []int{
2, 3, 5, 7, 11, 13, 17, 19,
} {
isPrime[n] = true
}
}
func count1s(n int) int {
cnt := 0
for n > 0 {
if n%2 == 1 {
cnt++
}
n >>= 1
}
return cnt
}
func countPrimeSetBits(left, right int) int {
cnt := 0
for n := left; n <= right; n++ {
if isPrime[count1s(n)] {
cnt++
}
}
return cnt
}
var _ = countPrimeSetBits

View file

@ -0,0 +1,23 @@
package q799
func champagneTower(poured, query_row, query_glass int) float64 {
buf := [100]float64{float64(poured)}
for r := range query_row + 1 {
var spill float64 = 0
for c := range r + 1 {
if r == query_row && c == query_glass {
return max(buf[c], 1)
}
if buf[c] > 1 {
buf[c] = (buf[c] - 1) / 2
buf[c], spill = buf[c]+spill, buf[c]
} else {
buf[c], spill = spill, 0
}
}
}
return 0
}
var _ = champagneTower