Skip to content

Commit 58144f6

Browse files
authored
Merge pull request #83 from learntosurf/main
Learntosurf / 11월 1주차 / 7문제
2 parents 7178295 + 73d0f74 commit 58144f6

11 files changed

+140
-1
lines changed

.DS_Store

0 Bytes
Binary file not shown.

learntosurf/.DS_Store

6 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: 2024-11-07-[BOJ]-#14717-앉았다","url":"/Users/learntosurf/Desktop/codingtest_algorithm_study/learntosurf/BruteForce/2024-11-07-[BOJ]-#14717-앉았다.py","tests":[],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/Users/learntosurf/Desktop/codingtest_algorithm_study/learntosurf/BruteForce/2024-11-07-[BOJ]-#14717-앉았다.py","group":"local","local":true}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
N = int(input())
2+
3+
for i in range(1, N+1):
4+
answer = i + sum((map(int, str(i))))
5+
if answer == N:
6+
print(i)
7+
break
8+
if i == N: # 생성자가 없는 경우
9+
print(0)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
heights = [int(input()) for _ in range(9)]
5+
6+
for i in range(9):
7+
for j in range(i + 1, 9):
8+
if sum(heights) - heights[i] - heights[j] == 100:
9+
result = [heights[k] for k in range(9) if k != i and k != j]
10+
result.sort()
11+
print(*result, sep='\n')
12+
exit()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Tn = [i * (i+1) // 2 for i in range(1, 46)]
2+
eureka = [0] * 10001
3+
4+
for i in range(Tn):
5+
for j in range(Tn):
6+
for k in range(Tn):
7+
if i+j+k <= 1000:
8+
eureka[i+j+k] = 1
9+
10+
T = int(input())
11+
for _ in range(T):
12+
print(eureka[int(input())])
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## 틀린 풀이 ##
2+
3+
from itertools import combinations
4+
from math import comb
5+
6+
cards = [i for i in range(1, 11)] * 2 # 20장의 카드 리스트 구성 (1~10 2장씩)
7+
8+
def judge(card1, card2):
9+
# 땡: 두 카드가 같을 경우
10+
if card1 == card2:
11+
return f"{card1}땡"
12+
13+
# 끗: 땡이 아닐 경우 두 카드의 합을 10으로 나눈 나머지
14+
else:
15+
sum_value = (card1 + card2) % 10
16+
return f"{sum_value}끗"
17+
18+
# 족보 우선순위 설정 (높은 족보일수록 더 높은 값)
19+
rank_order = {f"{i}땡": 10-i for i in range(1, 11)}
20+
rank_order.update({f"{i}끗": -i for i in range(10)}) # 끗 족보는 숫자가 클수록 강하지만 땡보다는 약함
21+
# 끗 족보에는 음수를 사용해 낮은 값을 할당하여, 땡 족보보다 낮은 순위로 설정
22+
23+
def win_probability(y_card1, y_card2):
24+
win_count = 0
25+
total_count = 0
26+
27+
y_rank = rank_order[judge(y_card1, y_card2)] # 영학이의 족보
28+
29+
# 상대방이 2장을 뽑는 모든 경우의 수
30+
for opp_card1, opp_card2 in combinations(cards, 2):
31+
32+
remaining_cards = cards.copy()
33+
remaining_cards.remove(opp_card1)
34+
remaining_cards.remove(opp_card2)
35+
36+
opp_rank = rank_order[judge(opp_card1, opp_card2)] # 상대방의 족보
37+
38+
total_count += 1
39+
40+
if y_rank > opp_rank: # 영학이가 이기는 경우의 수
41+
win_count += 1
42+
43+
probability = win_count / total_count
44+
return f"{probability:.3f}" # 소수점 셋째 자리까지 출력
45+
46+
y_card1, y_card2 = map(int, input().split())
47+
print(win_probability(y_card1, y_card2))
48+
49+
# print(win_probability(1, 1)) # 0.941
50+
# print(win_probability(1, 2)) # 0.275
51+
# print(win_probability(1, 9)) # 0.000
52+
# print(win_probability(10, 10)) # 1.000
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
m, n = map(int, input().split())
2+
plate = []
3+
count = []
4+
5+
for _ in range(m):
6+
plate.append(input())
7+
8+
for a in range(m-7):
9+
for b in range(n-7):
10+
W = 0
11+
B = 0
12+
for i in range(a, a+8):
13+
for j in range(b, b+8):
14+
if (i+j) % 2 == 0:
15+
if plate[i][j] != 'W':
16+
W += 1
17+
if plate[i][j] != 'B':
18+
B += 1
19+
else:
20+
if plate[i][j] != 'B':
21+
W += 1
22+
if plate[i][j] != 'W':
23+
B += 1
24+
count.append(min(W, B))
25+
26+
print(min(count))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
N, M = map(int, input().split())
2+
3+
rect = [[input() for _ in range(M)] for _ in range(N)]
4+
square = []
5+
for k in range(1, min(N, M)):
6+
for i in range(N):
7+
for j in range(M):
8+
if rect[i][j] == rect[i][j+k] == rect[i+k][j] == rect[i+k][j+k]:
9+
square.append((k+1)**2)
10+
exit()
11+
12+
print(max(square))

learntosurf/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)