인기 문제에 있는 꿀문제만 조져보았다.
백준 15637번: Lotto
구데기컵스럽게 이상한 문제인데 쉬운 편.
https://dhlottery.co.kr/gameResult.do?method=byWin
링크 아래쪽에서 친절하게 ~회부터 ~회까지 당첨번호를 엑셀로 다운받을 수 있다.
코드는 굳이 첨부하지 않는다.
백준 17202번: 핸드폰 번호 궁합
어릴 적에 한번쯤은 해보았을 듯한 이름 궁합과 비슷하다.
틀리기가 더 힘든 문제.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream>
using namespace std;
int main() {
char num1[9], num2[9];
int arr[16];
cin >> num1 >> num2;
for ( int i = 0; i < 8; ++i) {
arr[i * 2] = num1[i] - '0' ;
arr[i * 2 + 1] = num2[i] - '0' ;
}
for ( int i = 15; i >= 2; --i) {
for ( int j = 0; j < i; ++j) {
arr[j] = (arr[j] + arr[j + 1]) % 10;
}
}
cout << arr[0] << arr[1];
}
|
백준 17072번: 아스키 아트
원본 이미지의 RGB값이 주어졌을 때, 아스키 이미지를 출력하는 문제.
나와있는대로 구현하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int r, g, b;
for ( int i = 0; i < n; ++i) {
for ( int j = 0; j < m; ++j) {
cin >> r >> g >> b;
int i = 2126 * r + 7152 * g + 722 * b;
if (i < 510000) cout << '#' ;
else if (i < 1020000) cout << 'o' ;
else if (i < 1530000) cout << '+' ;
else if (i < 2040000) cout << '-' ;
else cout << '.' ;
}
cout << '\n' ;
}
}
|
백준 17074번: 정렬
주어진 길이 n의 배열에서, 수 하나를 빼었을 때 정렬된 배열이 되는 경우의 수가 몇 가지인지 구하는 문제이다.
순서가 거꾸로 되어있는 연속된 원소가 두 쌍 이상 있으면 당연히 0가지이고,
이미 정렬된 배열이면 당연히 n가지이다.
한 쌍이면 어떨까? 앞뒤 원소와 잘 비교해서 세주어야 한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector< int > arr(n);
for ( int i = 0; i < n; ++i) cin >> arr[i];
int op = 0, loc;
for ( int i = 1; i < n; ++i) {
if (arr[i - 1] > arr[i]) {
op++;
loc = i;
}
}
if (op >= 2) cout << 0;
else if (op == 1) {
int ans = 0;
if (loc == 1 || arr[loc] >= arr[loc - 2]) ans++;
if (loc == n - 1 || arr[loc + 1] >= arr[loc - 1]) ans++;
cout << ans;
}
else cout << n;
}
|
백준 17201번: 자석 체인
생략
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
char arr[20];
cin >> arr;
for ( int i = 1; i < n; ++i) {
if (arr[2 * i - 1] == arr[2 * i]) {
cout << "No" ;
return 0;
}
}
cout << "Yes" ;
}
|
백준 17206번: 준석이의 수학 숙제
어떤 자연수 N이 주어질 때, 3 또는 7의 배수를 모두 더한 값을 구하는 문제이다.
최대 10만 번 주어지므로, 그때그때 계산하기는 어렵다.
다만 N의 범위가 80000으로 작으므로 미리 전처리해주면 풀 수 있다.
N이 만약 엄청나게 크다면? 그 때는 (3의 배수의 합) + (7의 배수의 합) - (21의 배수의 합)을 통해 구하면 되겠다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int arr[80001] = {};
for ( int i = 1; i <= 80000; ++i) {
if (i % 3 == 0 || i % 7 == 0) arr[i] = arr[i - 1] + i;
else arr[i] = arr[i - 1];
}
int tc, n;
cin >> tc;
while (tc--) {
cin >> n;
cout << arr[n] << '\n' ;
}
}
|
백준 17142번: 연구소 3
N * N의 방에 바이러스와 벽의 위치가 주어지고, 바이러스 중 M개를 활성화시키면 바이러스가 전파된다.
어떤 바이러스를 고르냐에 따라 방 전체에 전파되는 시간이 다를텐데, 그 중 최소 시간을 구하는 구하는 문제이다.
다행히 바이러스의 갯수와 M이 10 이하이므로, 모든 경우를 다 해보면 된다.
전파되는 바이러스가 비활성 바이러스가 있는 칸으로 가면 비활성 바이러스가 활성된다는 점에 유의하자.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair< int , int > ii;
int pos[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector< vector< int > > arr(n, vector< int >(n));
vector< int > loc;
int virus = 0;
for ( int i = 0; i < n; ++i) for ( int j = 0; j < n; ++j) {
cin >> arr[i][j];
if (arr[i][j] == 2) {
virus++;
loc.push_back(i * 100 + j);
}
}
int ans = 10000;
vector< int > per(virus, 0);
for ( int i = 0; i < m; ++i) per[i] = 1;
do {
vector<vector< int > > temp = arr;
queue<ii> q;
for ( int i = 0; i < virus; ++i) if (per[i]) {
q.push(ii(loc[i], 0));
temp[loc[i] / 100][loc[i] % 100] = 3;
}
int now = 0;
while (!q.empty()) {
ii u = q.front();
q.pop();
int d = u.second;
for ( int k = 0; k < 4; ++k) {
int x = u.first / 100 + pos[k][0];
int y = u.first % 100 + pos[k][1];
if (x < 0 || y < 0 || x >= n || y >= n) continue ;
if (temp[x][y] == 0) {
now = max(now, d + 1);
temp[x][y] = 3;
q.push(ii(x * 100 + y, d + 1));
}
else if (temp[x][y] == 2) {
temp[x][y] = 3;
q.push(ii(x * 100 + y, d + 1));
}
}
}
bool b = 1;
for ( int i = 0; i < n; ++i) for ( int j = 0; j < n; ++j) {
if (temp[i][j] == 0) b = 0;
}
if (b) ans = min(ans, now);
} while (prev_permutation(per.begin(), per.end()));
if (ans == 10000) cout << -1;
else cout << ans;
}
|