※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 13242번 문제인 Harps and Tails이다.
문제는 아래 링크를 확인하자.

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

 

13242번: Harps and Tails

The first line of input contains 2 integers n and m (1 ≤ n, m ≤ 1000) representing the number of rows and columns of the grid.  The next n lines will describe the state of the grid. The i-th line will contain a string with n characters denoting the st

www.acmicpc.net

문제에서 주어지는 조건과 같이 열만을 조작할 수 있을 경우 어느 한 행을 모두 H로 만들면 그 행과 동일했던 다른 모든 행들이 모두 H가 되며, 다른 행들은 모두 H가 되지는 못하게 되는 점을 관찰하자.

 

위의 관찰로부터, 주어지는 행들 중 가장 많은 행의 그 개수를 출력하는 것으로 문제를 해결할 수 있다는 것을 알 수 있다.

 

이는 set 헤더의 multiset을 이용하면 쉽게 구해낼 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <set>
#include <string>
using namespace std;

int R, C;
multiset<string> st;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> R >> C;
	while (R--) {
		string s; cin >> s;
		st.insert(s);
	}

	int ans = 0;
	for (auto& x : st) {
		ans = max(ans, (int)st.count(x));
	}

	cout << ans;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 13241 // C++] 최소공배수  (0) 2023.05.25
[BOJ 13245 // C++] Sum of digits  (0) 2023.05.24
[BOJ 2244 // C++] 민코프스키 합  (0) 2023.05.22
[BOJ 10254 // C++] 고속도로  (0) 2023.05.21
[BOJ 9240 // C++] 로버트 후드  (0) 2023.05.20

+ Recent posts