JXNVCE ALGO-LOG YouJin Jung

BOJ-2565

기초 DP! aka 동적계획법

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int dp[102];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	int N, a, b;
    vector<pair<int, int>> v;
	cin >> N;
	v.emplace_back(0, 0);
  
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		v.emplace_back(a, b);
	}
  
	sort(v.begin(), v.end());
	
	int result = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < i; j++) 
			if ((v[i].second > v[j].second) && (dp[j] >= dp[i])) dp[i] = dp[j] + 1;
		result = max(result, dp[i]);
	}
	
	cout << N - result << endl;
	return 0;
}

image

BOJ-4949

스택을 활용한 문제

#include <iostream>
#include <string>
#include <stack>

using namespace std;

bool check(char c1, char c2){
    if ((c1=='(' && c2==')') || (c1=='[' && c2==']')) return true;
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    string str = "";
    while(1) {
        getline(cin, str);
        if (str.length()==1 && str[0]=='.') break;
        
        stack<char> s;
        bool flag = true;
        
        for (int i=0; i<str.length(); i++) {
            if(str[i]=='(' || str[i]=='[') s.push(str[i]);
            if(str[i]==')' || str[i]==']') {
                if (!s.empty()){            
                    if(check(s.top(), str[i])) s.pop();
                    else {
                        flag = false;
                        break;
                    }
                }
                else {  
                    flag = false;
                    break;
                }
            }
        }
        if (flag==false) cout << "no" << endl;
        else {
            if(s.empty()) {
                cout << "yes" << endl;
                continue;
            }
            else cout << "no" << endl;
        }
    }    
    return 0;
}

오늘 너무 창피하고 창피하다 반성해야지 ㅜㅜ… 앞으로는 더더 열심히 할테니 제발 좋은 일들만 있게 해주세요…제발제발…🙏🏼🙏🏼🙏🏼

BOJ-2606

DFS로 풀리는 문제… 아직도 헷갈려 어질어질

#include <iostream>
#include <vector>

using namespace std;

vector<int> virus[101];
bool check[101];

int dfs_count(int x) {
    int count=0;
    check[x] = true;
    for (int i=0; i<virus[x].size(); i++) {
	int y = virus[x][i];
	if (!check[y]) {
	    dfs_count(y);
	    count++;
	}
    }
    return count;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, m;
    cin >> n >> m;
    for (int i=0; i<m; i++) {
	int u, v;
	cin >> u >> v;
	virus[u].push_back(v);
	virus[v].push_back(u);
    }
    int ans = dfs_count(1);
    cout << ans << endl;
}

너무 기대를 많이 하고 김칫국도 많이 마셨더니 현실을 부정하게된다… 에이 설마~ 아닐거야 에이~ 아닐거야….. 나한테만은…이라는 이기적인 생각 ㅜㅜ 머리가 아프다… 눈물도 날 것 같다ㅜㅜ 화도 난다… 얼른 자자!

BOJ-2941

#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    vector<string> vec = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="};
    int index = 0;
    string S;
    cin >> S;
    for(int i=0; i<vec.size(); i++){
        index = S.find(vec[i]);
        for(auto &a: S)
            if (a==index) S.replace(index, vec[i].length(), "#");
    }
    cout << S.length();
}

BOJ-3009

기본 수학 연산 카테고리에 제일 정답률이 높았던 문제!@@!@!

#include <iostream>

using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);
	  int x[4], y[4];
    for (int i = 0; i < 3; i++) cin >> x[i] >> y[i];
 
    x[3] = x[0];
    y[3] = y[0];

    if (x[3] == x[1]) x[3] = x[2];
    else if (x[3] == x[2]) x[3] = 1;

    if (y[3] == y[1]) y[3] = y[2];
    else if (y[3] == y[2]) y[3] = y[1];

    cout << x[3] << " " << y[3] << endl;
    return 0;
}

image