본문 바로가기

반응형

백준

(29)
백준 1260번: DFS와 BFS C++코드(DFS, BFS) #include #include #include #include #include using namespace std; vector maps[1001]; void dfs(int v){ stack s; int visited[1001] = {0,}; s.push(v); while(!s.empty()){ int now = s.top(); if(visited[now] == 0){ cout m >> v; for(int i=0; i> node1 >> node2; maps[node1].push_back(node2); maps[node2].push_back(node1); } for(int i=1; i
백준 1476번: 날짜 계산 C++코드(브루트포스, Bruteforce) #include using namespace std; int main(){ int e,s,m; int count = 0;; int re=0,rs=0,rm=0; cin >> e >> s >> m; while(1){ if(re == 16){ re = 1; } if(rs == 29){ rs = 1; } if(rm == 20){ rm = 1; } if(re == e & rs == s & rm == m){ cout
백준 2512번: 예산 C++코드(이진 탐색) #include using namespace std; int values[10001]; int search(int n,int m, int standard){ int result = 0; for(int i=0; i
백준 1926번: 그림 C++코드(BFS) #include #include #include #include #include using namespace std; int n,m; int picture[501][501]; int visit[501][501] = {0,}; int x[4] = {0,0,1,-1}; int y[4] = {1,-1,0,0}; int bfs(int s1, int s2){ int funcnt = 0; queue q; q.push(make_pair(s1,s2)); while(!q.empty()){ funcnt += 1; pair now = q.front(); q.pop(); for(int i=0; i> m; vector v; v.push_back(0); for(int i=0; i picture[i][j]; } } for(int ..
백준 2193번: 이친구 C++코드(DP, 다이나믹 프로그래밍) #include using namespace std; long long arr[100] = {0,}; long long dp(int n){ if(n n; arr[1] = 1; arr[2] = 1; cout
백준 1181번: 단어 정렬 C++코드(정렬) #include #include #include #include #include using namespace std; bool cmp(const string & a, const string & b){ if(a.length() < b.length()) return true; else if(a.length() == b.length()){ if(a < b) return true; } return false; } int main(){ int n; char temp[51]; vector words; scanf("%d", &n); for(int i=0; i
백준 3046번: R2 C언어 코드(구현, 사칙연산) #include int main(){ int r1, s; scanf("%d %d", &r1, &s); printf("%d", s+(s-r1)); } 설명 S가 평균이므로 S에 S와 R1의 차이만큼 더해주면 R2가 나온다. 문제점 없다.
백준 1932번: 정수 삼각형 C++코드(DP, 다이나믹 프로그래밍) #include #include using namespace std; int arr[501][501]; int cost[501][501] = {0,}; int n; void dp(){ for(int i=0; i

반응형