본문 바로가기

CodingTest Exam

(110)
2-5. 최대 선호 음식(DFS, 비트연산) ★★★★★ #include #include using namespace std; int n, d, k; int ch[16]; bool flag = false; int cnt = 0, res = 0; vector V[30001]; void DFS(int L, int s) { if(L == k) { for(int i = 1; i k) continue; for(int j = 0; j n >> d >> k; int a, b; for(int i =..
2-4. 숲속의 기사 ★★★★☆ #include #include #include using namespace std; struct Pos { int x; int y; Pos(int x, int y) { this -> x = x; this -> y = y; } }; int dis[2][1001][1001]; int main() { int w, h, res = 2147000000; cin >> w >> h; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; queue Q1; queue Q2; vector Map(h, vector(w, 0)); for(int i = 0; i > Map[i][j]; if(Map[i]..
2-3. 멀티태스킹(효율성) ★★★★☆ #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n; vector T(n+1, 0); vector ST(n+1, 0); for(int i = 1; i > T[i]; ST[i] = T[i]; } cin >> k; sort(ST.begin(), ST.end()); long long rest = n; for(int i = 1; i = cycle) { k -= cycle; rest--; } else { int cnt = k % rest; int pos = 0; for(int j = 1; j = ST[i]) { if(cnt == p..
2-2. 모든 아나그램 (해쉬, 슬라이딩 윈도우) ★★★☆☆ #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; string t; map ana; map tmp; cin >> s >> t; int count = 0; int lt = 0, rt = t.size()-1; for(int i = 0; i < t.size(); i++) ana[t[i]]++; for(int i = 0; i < rt; i++) tmp[s[i]]++; for(int rt = t.size()-1 ; rt < s.size(); rt++) { tmp[s[rt]]++; if(ana == tmp) count++; tmp[s[lt]]--; if(tmp[s[lt]] ..
2-1. 숨겨진 합 ★★☆☆☆ #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string str; string temp; cin >> str; vector num; for(int i = 0; i < str.size(); i++) { if(isdigit(str[i])) { temp += str[i]; } else { if(!temp.empty()) { num.push_back(stoi(temp)); temp.clear(); } } } if(!temp.empty()) num.push_back(stoi(temp)); int sum = 0; for(int i = 0; i < num...
1-5. 효율적인 공부 ★★★☆☆ #include #include #include using namespace std; struct Study { int st; int et; int e; Study(int x, int y, int z) { this -> st = x; this -> et = y; this -> e = z; } bool operator> n >> m >> r; for(int i = 0; i > a >> b >> c; V.push_back(Study(a, b, c)); } sort(V.begin(), V.end()); dy[0] = V[0].e; for(int i = 1; i = ..
1-4. 바둑대회(DFS) ★★★★☆ #include #include #include using namespace std; int abil[2][16]; int ch[16]; int n, res = 2147000000; void DFS(int s, int L) { if(L == n/2) { vector A, B; for(int i = 0; i < n; i++) { if(ch[i] == 1) A.push_back(i); else B.push_back(i); } int sumA = 0, sumB = 0; for(int i = 0; i < A.size(); i++) { sumA += abil[0][A[i]]; sumB += abil[1][B[i]]; } res = min(res, abs(sumA - sumB)); } else { for(int i..
1-3. 영화 관람 ★★★☆☆ #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, idx, max = 0; cin >> n; vector V(n+1, 0); vector ans(n+1, 0); for(int i = 1; i > V[i]; } ans[1] = 0; for(int i = 2; i