단계별로 풀기 - 브루트포스
규칙을 찾지 않아도 되는 편안함..?
2231 분해합
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
int N;
cin >> N;
for (int i=1; i<=N; i++) {
int sum = i;
string a = to_string(i);
for (int i=0; i<a.size(); i++) {
sum += a[i] - '0';
}
if (sum == N) {
cout << i << "\n";
return 0;
}
}
cout << 0 << "\n";
return 0;
}
7568 덩치
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
int main(int argc, const char * argv[]) {
vector<pii> v;
int rank[51] = {0};
int N, x, y;
cin >> N;
for (int i=0; i<N; i++) {
cin >> x >> y;
v.push_back(make_pair(x, y));
}
for (int i=0; i<N; i++) {
int k=1;
for (int j=0; j<N; j++) {
if (i != j) {
if (v[i].first < v[j].first && v[i].second < v[j].second) {
k++;
}
}
}
rank[i] = k;
}
for (int i=0; i<N; i++) {
cout << rank[i] << " ";
}
cout << "\n";
return 0;
}
1018 체스판 다시 칠하기
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int N, M;
char board[51][51];
char white[8][8];
char black[8][8];
bool isIn(int x, int y) {
return (x+7) < N && (y+7) < M;
}
int square(int x, int y) {
int w=0, b=0;
if (isIn(x, y)) {
for (int i=0; i<8; i++) {
for(int j=0; j<8; j++) {
if (board[x+i][y+j] == white[i][j]) {
w++;
}
if (board[x+i][y+j] == black[i][j]) {
b++;
}
}
}
}
else {
return 0;
}
return max(w, b);
}
int main(int argc, const char * argv[]) {
string input;
cin >> N >> M;
for (int i=0; i<8; i++) {
for(int j=0; j<8; j++) {
if (i%2 == 0 && j%2 == 0) {
white[i][j] = 'W';
black[i][j] = 'B';
}
else if (i%2 == 1 && j%2 == 0) {
white[i][j] = 'B';
black[i][j] = 'W';
}
else if (i%2 == 0 && j%2 == 1) {
white[i][j] = 'B';
black[i][j] = 'W';
}
else {
white[i][j] = 'W';
black[i][j] = 'B';
}
}
}
for (int i=0; i<N; i++) {
cin >> input;
for (int j=0; j<input.size(); j++) {
board[i][j] = input[j];
}
}
int res=0;
for (int i=0; i<N; i++) {
for (int j=0; j<M; j++) {
res = max(res, square(i, j));
}
}
cout << 64-res << "\n";
return 0;
}
1436 영화감독 숌
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
int N, cnt = 0, i=666;
cin >> N;
while(1) {
string s = to_string(i);
for (int j=0; j<(int)s.size()-2; j++) {
if(s[j] == '6' && s[j+1] == '6' && s[j+2] == '6') {
cnt++;
break;
}
}
if (cnt == N) {
cout << i << "\n";
return 0;
}
i++;
}
}
'ALGORITHM > OTHER' 카테고리의 다른 글
[c++] 1654 랜선 자르기 (파라메트릭 서치(Parametric Search)) (0) | 2021.01.28 |
---|---|
[c++] 14425 문자열 집합 - Trie (트라이), set, unordered_set (0) | 2021.01.24 |
14621 나만 안되는 연애 (2) | 2021.01.06 |
12789 도키도키 간식드리미 (0) | 2021.01.06 |
11585 속타는 저녁 메뉴 (0) | 2020.12.28 |