목록브루트포스 (34)
정화 코딩

https://www.acmicpc.net/problem/15686 일단 모든 집과 모든 치킨집의 쌍에 대해서 거리를 구하기 위해서 집의 개수만큼 bfs를 돌렸다. (근데 생각해보니 bfs 쓸 필요 없이 좌표만 빼서 거리를 구할 수 있다.)그 결과(모든 집과 모든 치킨집의 쌍에 대한 거리)를 sp 배열에 담아두었다.그 후, 백트래킹으로 가능한 모든 치킨집 조합에 대해서 도시의 치킨 거리를 계산한다. 그 중 가장 최소인 값을 출력하면 된다. #include #include #include using namespace std;int dx[] = {1, -1, 0, 0};int dy[] = {0, 0, 1, -1};int n, m, hn, cn;int ans = 1000000;vector cchk;vector..

https://www.acmicpc.net/problem/1111 #include #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector arr(n); for (int i = 0; i > arr[i]; set ans; for (int a = -200; a 2) cout 무지성으로 모든 a, b 조합을 체크해서 풀었다...처음에는 a와 b 범위 모두 -100 ~ 100으로 잡았다가 WA를 받았다. 그 후 범위가 부족함을 깨닫고 범위를 늘려줬다. 무지성으로 너무 늘리면 또 시간초과를 ..

https://www.acmicpc.net/problem/23817 이 문제 풀 때 고수들이 옆에 있었어서 그들이 걍 다 해줌. 저는 풀이를 듣고 음 그렇구나. 천재다. 구현해볼게. 했음다. 첫번째 풀이. vst 배열: 현재 위치 (i, j) + 어느어느식당 방문했는지 (길이가 20인 비트스트링) 길이가 20인 비트스트링 → 2^20 하면 너무 큼 → 근데 어차피 최대가 5개 켜지는 거임 → 2^20 중에 안 쓰는 게 너무 많음 (어떤 걸 안 쓰는지 모름) → map 이용 vector>> → 최단 거리를 두번째 int에 저장하는 셈 vector>> (= vector>>) → 방문 했는지 안 했는지를 bool에 저장하는 셈 근데 이렇게 하면 터짐... 두번째 풀이.모든 식당과 식당 (+시작점) 사이의 거..

https://www.acmicpc.net/problem/32649 #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, k; cin >> a >> b >> k; vector ans; ans.push_back(a); ans.push_back(b); for (int i = a + 1; i = k) { for (int i = 0; i 캐어려운 정수론 문제인줄 알았는데 그냥 브루트포스 문제였다 ㅎㅎ;;핵심 포인트는 d는 A의 배수이면서 B의 약수여야 한다는 것이다. 그런데 A와 B의 범위가 그렇게 ..

https://www.acmicpc.net/problem/1359 #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long f[11]; f[0] = 1; for (int i = 1; i > n >> m >> k; cout.precision(10); int ans = 0; for (int i = k; i 수식은 아래와 같다.시그마 안에 있는 식을 정리하면 아래와 같다.그런데 아래와 같이 구현하면 WA를 받게 된다.for (int i = k; i 답을 이렇게 계산하면 8 7 1 를 입력했을 때 1.02290799..
5회차 - 브루트포스, 이분탐색 수학은 비대면강의입니다https://www.acmicpc.net/problem/19532모든 x와 y에 대해서 조건을 체크해주면 됩니다.#include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; // -999부터 999까지 가능한 x, y 값을 전부 탐색 for (int x = -999; x 마인크래프트https://www.acmicpc.net/problem/18111높이를 계속 바꿔서 고정해놓고 계산하는 방식으로 구..

https://www.acmicpc.net/problem/9048 #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int f, r, n; cin >> f >> r >> n; int ans = 2 * f + (r + 1); vector up(f + 1, 0); vector down(f + 1, r + 1); for (int i = 0; i > a >> b; if (b 처음에는 각 ..

https://www.acmicpc.net/problem/5534 #include #include using namespace std;int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int ss = s.size(); int ans = 0; for (int i = 0; i > st; int sts = st.size(); bool psb = false; for (int j = 0; j = ss) { psb = true; ..