20250809 baekjoon
This commit is contained in:
parent
b5dafd864e
commit
287d0b2a36
43
code_study/Baekjoon/swift/1074.swift
Normal file
43
code_study/Baekjoon/swift/1074.swift
Normal file
@ -0,0 +1,43 @@
|
||||
import Foundation
|
||||
|
||||
if let input = readLine(),
|
||||
let nums:[Int] = {
|
||||
let temp = input.split(separator: " ").compactMap({Int($0)})
|
||||
return temp.count == 3 ? temp : nil
|
||||
}(){
|
||||
var (N, r, c) = (nums[0],nums[1],nums[2])
|
||||
|
||||
var n = N
|
||||
var result = 0
|
||||
|
||||
while n > 0 {
|
||||
let half = Int(pow(2.0, Double(n-1)))
|
||||
let quatorArea = half * half
|
||||
|
||||
switch (r,c)
|
||||
{
|
||||
case (0..<half, 0..<half) :
|
||||
break
|
||||
case (0..<half, half..<2*half) :
|
||||
result += quatorArea
|
||||
c -= half
|
||||
case (half..<2*half, 0..<half) :
|
||||
result += quatorArea*2
|
||||
r -= half
|
||||
case (half..<2*half, half..<2*half) :
|
||||
result += quatorArea*3
|
||||
c -= half
|
||||
r -= half
|
||||
default :
|
||||
break
|
||||
}
|
||||
|
||||
n -= 1
|
||||
}
|
||||
|
||||
print(result)
|
||||
|
||||
}
|
||||
else{
|
||||
print("error")
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user