728x90
문제
2차원 평면에 n 명의 사람이 있다. i 번 사람의 좌표는 두 자연수 yi, xi 로 표현되고, 같은 위치에 여러 사람이 존재할 수 있다. 혼자 있는 사람의 수를 출력하여라.
입력
첫 줄에 n 이 주어진다.
두 번째 줄부터 n 줄에 걸쳐 yi, xi 가 주어진다
(1 ≤ n ≤ 100,000, 1 ≤ yi, xi ≤ 100)
출력
혼자 있는 사람의 수를 출력한다.
입력의 예 1
6
1 1
2 3
2 2
1 3 1 1 4 5
출력의 예 1
4
입력의 예 2
5
1 1
1 1
1 1
2 2
3 3
출력의 예 2
2
입력의 예 3
5
1 1
1 2
1 3
1 1
2 2
출력의 예 3
3
입력의 예 4
6
1 1
1 1
1 1
2 2
3 3
3 3
출력의 예 4
1
#코드 : 딕셔너리를 통한 풀이법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import sys
if __name__ == "__main__":
input = sys.stdin.readline
n = int(input())
myDic = {}
for i in range(n):
y, x = map(int, input().split())
temp_key = str(y)+'/'+str(x)
try :
myDic[temp_key] += 1
except:
myDic[temp_key] = 1
cnt = 0
for k, v in myDic.items():
if v == 1:
cnt += 1
print(cnt)
|
cs |
# 코드2 : 배열을 통한 풀이법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import sys
if __name__ == "__main__":
arr = [[0]*110 for _ in range(110)]
x = [0]*100010
y = [0]*100010
input = sys.stdin.readline
n = int(input())
tot_cnt = 0
for i in range(1, n+1):
x[i], y[i] = map(int, input().split())
for i in range(1, n+1):
arr[x[i]][y[i]] += 1
for i in arr:
for j in i:
if j == 1:
tot_cnt += 1
print(tot_cnt)
|
cs |
반응형