Baekjoon 17027번 [Shell Game]

https://www.acmicpc.net/problem/17027

 

17027번: Shell Game

The first line of the input file contains an integer $N$ giving the number of swaps ($1 \leq N \leq 100$). Each of the next $N$ lines describes a step of the game and contains three integers $a$, $b$, and $g$, indicating that shells $a$ and $b$ were swappe

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 구현, 시뮬레이션

 


 

문제

 

 


 

코드

 

더 좋은 방법이 있을 것 같기도 함

 

start_1, ans_1 = [0, 1, 0, 0], 0
start_2, ans_2 = [0, 0, 1, 0], 0
start_3, ans_3 = [0, 0, 0, 1], 0

N = int(input())
for i in range(N):
    a, b, g = map(int, input().split())
    start_1[a], start_1[b] = start_1[b], start_1[a]
    start_2[a], start_2[b] = start_2[b], start_2[a]
    start_3[a], start_3[b] = start_3[b], start_3[a]
    if start_1[g] == 1:
        ans_1 += 1
    if start_2[g] == 1:
        ans_2 += 1
    if start_3[g] == 1:
        ans_3 += 1
        
print(max(ans_1, ans_2, ans_3))

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 16770번 The Bucket List  (0) 2022.10.12
[백준] 16769번 Mixing Milk  (0) 2022.10.12
[백준] 15593번 Lifeguards (Bronze)  (0) 2022.10.03
[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03

Baekjoon 16770번 [The Bucket List]

https://www.acmicpc.net/problem/16770

 

16770번: The Bucket List

In this example, FJ needs 4 buckets: He uses buckets 1 and 2 for milking cow 3 (starting at time 2). He uses bucket 3 for milking cow 1 (starting at time 4). When cow 2 arrives at time 8, buckets 1 and 2 are now available, but not bucket 3, so he uses buck

www.acmicpc.net

 

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 구현

 


 

 

문제

 

 


 

코드

 

문제 설명) N개의 소에 대해 우유를 짜내기 시작하는 시간(s), 우유 짜내는 것을 종료하는 시간(t), 우유를 짜는데 필요한 양동이 수(b)가 주어짐. 한 번에 필요한 최대 양동이의 수를 구하면 됨! (단, 여러 마리의 소를 동시에 짤 수 있음)

 

N = int(input())

bucketList = [0]*1001
for i in range(N):
    si, ti, bi = map(int, input().split())
    bucketList[si] += bi # 시작 시간에는 bucket 필요 갯수만큼 더해서 표시
    bucketList[ti] -= bi # 종료 시간에는 bucket 필요 갯수만큼 빼서 표시

bucket = 0
ans = 0    
for i in range(len(bucketList)):
    bucket += bucketList[i] # bucketList[i] != 0 일 때 갱신됨
    ans = max(ans, bucket) # 이전까지의 최대 bucket 필요 갯수(ans)와 현재 bucket 필요 갯수(bucket) 중 더 큰 값으로 갱신

print(ans)

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 17027번 Shell Game  (0) 2022.10.12
[백준] 16769번 Mixing Milk  (0) 2022.10.12
[백준] 15593번 Lifeguards (Bronze)  (0) 2022.10.03
[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03

Baekjoon 16769번 [Mixing Milk]

https://www.acmicpc.net/problem/16769

 

16769번: Mixing Milk

The first line of the input file contains two space-separated integers: the capacity $c_1$ of the first bucket, and the amount of milk $m_1$ in the first bucket. Both $c_1$ and $m_1$ are positive and at most 1 billion, with $c_1 \geq m_1$. The second and t

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 수학, 구현, 시뮬레이션, 사칙연산

 


 

문제

 

 

 


 

코드

 

물 붓기 작업을 100회 밖에 안하므로 크게 고민하지 않고 단순 구현으로 풀었음

 

c1, m1 = map(int, input().split())
c2, m2 = map(int, input().split())
c3, m3 = map(int, input().split())

for i in range(1, 101):
    if i % 3 == 1:
        mix = min(c2-m2, m1)
        m2 += mix
        m1 -= mix
    elif i % 3 == 2:
        mix = min(c3-m3, m2)
        m3 += mix
        m2 -= mix
    else:        
        mix = min(c1-m1, m3)
        m1 += mix
        m3 -= mix
        
print(m1, m2, m3, sep='\n')

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 17027번 Shell Game  (0) 2022.10.12
[백준] 16770번 The Bucket List  (0) 2022.10.12
[백준] 15593번 Lifeguards (Bronze)  (0) 2022.10.03
[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03

Baekjoon 15593번 [Lifeguards (Bronze)]

https://www.acmicpc.net/problem/15593

 

15593번: Lifeguards (Bronze)

The first line of input contains $N$ ($1 \leq N \leq 100$). Each of the next $N$ lines describes a lifeguard in terms of two integers in the range $0 \ldots 1000$, giving the starting and ending point of a lifeguard's shift. All such endpoints are distinct

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 브루트포스 알고리즘

 


 

문제

 

 


 

코드

 

N = int(input())
lifeguards = [0]*1000
work = [] # 근무 시간 저장할 리스트
for _ in range(N):
    start, end = map(int, input().split())
    work.append((start, end))
    for i in range(start, end):
        lifeguards[i] += 1

ans = 0
for w in work:
    start, end = w[0], w[1]
    for i in range(start, end): # 현재 근무 시간을 빼기
        lifeguards[i] -= 1
    time = 0    
    for lifeguard in lifeguards: # 커버 가능한 최대 시간 계산
        if lifeguard > 0:        
            time += 1
    ans = max(time, ans) # ans 갱신  
    for i in range(start, end): # 다시 현재 근무 시간 더해주기
        lifeguards[i] += 1  
        
print(ans)

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 16770번 The Bucket List  (0) 2022.10.12
[백준] 16769번 Mixing Milk  (0) 2022.10.12
[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03
[백준] 15751번 Teleportation  (0) 2022.10.03

Baekjoon 14530번 [The Lost Cow]

https://www.acmicpc.net/problem/14530

 

14530번: The Lost Cow

The single line of input contains two distinct space-separated integers \(x\) and \(y\). Both are in the range \(0 \ldots 1,000\).

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 수학, 구현, 시뮬레이션

 


 

문제

 

 


코드

 

문제의 조건을 잘 확인해야 함

처음엔 이동한 후 위치에서 +1, -2, +4, -8, ... 이런 식으로 이동하는 건줄 알았는데, 알고 보니 처음 John의 위치인 x에서 +1, -2, +4, -8, ... 인 위치로 이동하는 거였음

 

x, y = map(int, input().split())
cur_John = x # John의 현재 위치
travel_distance, travel_direction = 1, 1 # 이동 거리, 이동 방향
idx = 1
ans = 0
while True:
    for _ in range(travel_distance):
        cur_John += travel_direction
        ans += 1
        if cur_John == y:
            print(ans)
            exit()
    idx *= 2 # 이동할 위치는 x로부터 2배씩 멀어짐       
    travel_distance = abs(cur_John-x) + idx 
    travel_direction *= (-1)

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 16769번 Mixing Milk  (0) 2022.10.12
[백준] 15593번 Lifeguards (Bronze)  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03
[백준] 15751번 Teleportation  (0) 2022.10.03
[백준] 10675번 Cow Routing  (0) 2022.10.03

Baekjoon 14175번 [The Cow-signal]

https://www.acmicpc.net/problem/14175

 

14175번: The Cow-Signal

Bessie and her cow friends are playing as their favorite cow superheroes. Of course, everyone knows that any self-respecting superhero needs a signal to call them to action. Bessie has drawn a special signal on a sheet of M×N paper (1≤M≤10,1≤N≤10)

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 구현, 문자열

 


 

문제

 

 


코드

 

M, N, K = map(int, input().split())
signal = []
for m in range(M):
    tmp = input()
    signal.append(tmp)
   
for s in signal:
    for k in range(K):
        for c in s:
            print(c*K, end='')
        print('')

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 15593번 Lifeguards (Bronze)  (0) 2022.10.03
[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 15751번 Teleportation  (0) 2022.10.03
[백준] 10675번 Cow Routing  (0) 2022.10.03
[백준] 11970번 Fence Painting  (0) 2022.10.03

Baekjoon 15751번 [Teleportation]

https://www.acmicpc.net/problem/15751

 

15751번: Teleportation

The first and only line of input contains four space-separated integers: $a$ and $b$, describing the start and end locations, followed by $x$ and $y$, describing the teleporter. All positions are integers in the range $0 \ldots 100$, and they are not neces

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 수학, 구현, 사칙연산

 


 

문제

 

 


 

코드

 

a, b, x, y = map(int, input().split())
a, b = min(a, b), max(a, b)
x, y = min(x, y), max(x, y) 
distance = b-a 
teleporter = abs(x-a)+abs(y-b)
ans = min(distance, teleporter)
    
print(ans)

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03
[백준] 10675번 Cow Routing  (0) 2022.10.03
[백준] 11970번 Fence Painting  (0) 2022.10.03
[백준] 14173번 Square Pasture  (0) 2022.10.02

Baekjoon 10675번 [Cow Routing]

https://www.acmicpc.net/problem/10675

 

10675번: Cow Routing

Tired of the cold winter weather on her farm, Bessie the cow plans to fly to a warmer destination for vacation.  Unfortunately, she discovers that only one airline, Air Bovinia, is willing to sell tickets to cows, and that these tickets are somewhat compl

www.acmicpc.net

 

  • 사용언어: Python (PyPy3)
  • 알고리즘: 구현

 


 

문제

 

 


 

코드

 

처음에는 여러 비행기를 타도 되는 줄 알고 왜 이게 브론즈 문제일까 고민했다..

 

A, B, N = map(int, input().split())
ans = 1001
for i in range(N):
    cost, num = map(int, input().split())
    ListOfCities = list(map(int, input().split()))
    Departures = False
    for city in ListOfCities:
        if A == city: # 출발지에 도착한 경우
            Departures = True 
        elif B == city: # 도착지에 도착한 경우
            if not Departures: # 출발지를 아직 거쳐오지 않은 경우
                break
            else: # 출발지를 거쳐온 경우
                if cost < ans:
                    ans = cost
if ans != 1001:
    print(ans)
else:
    print(-1)

 

 

'백준 > USACO bronze 기출' 카테고리의 다른 글

[백준] 14530번 The Lost Cow  (0) 2022.10.03
[백준] 14175번 The Cow-Signal  (0) 2022.10.03
[백준] 15751번 Teleportation  (0) 2022.10.03
[백준] 11970번 Fence Painting  (0) 2022.10.03
[백준] 14173번 Square Pasture  (0) 2022.10.02

+ Recent posts