λΈλ£¨νΈ ν¬μ€(Brute Force)
μ°μ°μ΄ 1μ΅νκ° μ λμ΄κ° λ λͺ¨λ κ²½μ°μ μλ₯Ό κ²μ¬νλ μκ³ λ¦¬μ¦μΌλ‘ μμ νμμ΄λΌκ³ λ νλ€.
λ¬Έμ
https://www.acmicpc.net/problem/1018
1018λ²: 체μ€ν λ€μ μΉ νκΈ°
첫째 μ€μ Nκ³Ό Mμ΄ μ£Όμ΄μ§λ€. Nκ³Ό Mμ 8λ³΄λ€ ν¬κ±°λ κ°κ³ , 50λ³΄λ€ μκ±°λ κ°μ μμ°μμ΄λ€. λμ§Έ μ€λΆν° Nκ°μ μ€μλ 보λμ κ° νμ μνκ° μ£Όμ΄μ§λ€. Bλ κ²μμμ΄λ©°, Wλ ν°μμ΄λ€.
www.acmicpc.net
#include <iostream>
#include <algorithm>
using namespace std;
bool board[50][50];
int compare(int x, int y, bool white)
{
int cnt = 0;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (white != board[x + i][y + j])
cnt++;
white = !white;
}
white = !white;
}
return cnt;
}
int main(void)
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
char c;
cin >> c;
if (c == 'W')
board[i][j] = true;
}
int ans = 64;
for (int i = 0; i < n - 7; ++i)
for (int j = 0; j < m - 7; ++j)
ans = min(ans, min(compare(i, j, true), compare(i, j, false)));
cout << ans;
return 0;
}
https://www.acmicpc.net/problem/1436
1436λ²: μνκ°λ μ
666μ μ’ λ§μ λνλ΄λ μ«μλΌκ³ νλ€. λ°λΌμ, λ§μ λΈλ‘λ²μ€ν° μνμμλ 666μ΄ λ€μ΄κ° μ λͺ©μ λ§μ΄ μ¬μ©νλ€. μνκ°λ μμ μΈμμ μ’ λ§ μ΄λΌλ μλ¦¬μ¦ μνμ κ°λ μ΄λ€. μ‘°μ§ λ£¨μΉ΄μ€λ μ€νμμ¦λ₯Ό λ§λ€ λ, μ€νμμ¦ 1, μ€νμμ¦ 2, μ€νμμ¦ 3, μ€νμμ¦ 4, μ€νμμ¦ 5, μ€νμμ¦ 6κ³Ό κ°μ΄ μ΄λ¦μ μ§μκ³ , νΌν° μμ¨μ λ°μ§μ μ μμ λ§λ€ λ, λ°μ§μ μ μ 1, λ°μ§μ μ μ 2, λ°μ§μ μ μ 3κ³Ό κ°μ΄ μν μ λͺ©μ μ§μλ€. νμ§λ§ μμ μμ μ΄ μ‘°
www.acmicpc.net
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int n;
cin >> n;
int ans = 666, cnt = 0;
while (n != 0) {
string value = to_string(ans++);
for (int j = 0; j < value.length() - 2; j++)
if (value.substr(j, 3) == "666") {
n--;
if (n == 0)
ans--;
break;
}
}
cout << ans;
return 0;
}