문제 출처:
https://codeforces.com/contest/1676/problem/C
문제 분석:
브루트포스
문제 해결:
단어끼리 뺐을때 가장 적은 차이값을 구하는 문제이다
그대로 모두 계산해서 구하면된다.
내 소스코드:
// freopen("input.txt", "r", stdin);
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <list>
#include <set>
#include <string.h>
#include <map>
#include <limits.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 987654321;
int testcase;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> testcase;
while (testcase--)
{
int n, m;
string tmp;
string l[52];
int ans = INF;
cin >> n >> m;
rep(i, n)
{
cin >> tmp;
l[i] = tmp;
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
int sum = 0;
for (int k = 0; k < m; k++)
{
sum += abs(l[i][k] - l[j][k]);
}
ans = min(ans, sum);
}
}
cout << ans << "\n";
}
return 0;
}
고찰:
'알고리즘 > 알고리즘 문제풀이' 카테고리의 다른 글
Codeforces Round #790 (Div. 4) - E (0) | 2022.05.15 |
---|---|
Codeforces Round #790 (Div. 4) - D (0) | 2022.05.15 |
Codeforces Round #790 (Div. 4) - B (0) | 2022.05.15 |
Codeforces Round #790 (Div. 4) - A (0) | 2022.05.15 |
21922번: 학부 연구생 민상 (0) | 2022.02.14 |