문제링크 : https://www.acmicpc.net/problem/6593 6593번: 상범 빌딩 당신은 상범 빌딩에 갇히고 말았다. 여기서 탈출하는 가장 빠른 길은 무엇일까? 상범 빌딩은 각 변의 길이가 1인 정육면체(단위 정육면체)로 이루어져있다. 각 정육면체는 금으로 이루어져 있어 www.acmicpc.net #include using namespace std; #define ll long long struct xyz { int x, y, z; }; char field[30][30][30]; int visited[30][30][30]; queueq; int L, R, C; int dx[6] = {1,-1,0,0,0,0}; //동서 int dy[6] = {0,0,1,-1,0,0}; //남북 int..
문제링크 : https://www.acmicpc.net/problem/13023 13023번: ABCDE 문제의 조건에 맞는 A, B, C, D, E가 존재하면 1을 없으면 0을 출력한다. www.acmicpc.net #include using namespace std; #define ll long long bool check; vector v[2000]; bool visited[2000]; void dfs(int i, int depth) { if(depth == 4) { check = true; return; } visited[i] = true; //방문처리 for(int index = 0; index < v[i].size(); index++) { if(!visited[v[i][index]]) { df..
문제링크 : https://www.acmicpc.net/problem/17425 17425번: 약수의 합 두 자연수 A와 B가 있을 때, A = BC를 만족하는 자연수 C를 A의 약수라고 한다. 예를 들어, 2의 약수는 1, 2가 있고, 24의 약수는 1, 2, 3, 4, 6, 8, 12, 24가 있다. 자연수 A의 약수의 합은 A의 모든 약수를 더 www.acmicpc.net #include using namespace std; #define ll long long #define MAX 1000000 ll dp[MAX]; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int T, N; for(int i=1; i> N; cout i가 약수..
문제링크 : https://www.acmicpc.net/problem/2548 2548번: 대표 자연수 첫째 줄에는 자연수의 개수 N이 입력된다. N은 1 이상 20,000 이하이다. 둘째 줄에는 N개의 자연수가 빈칸을 사이에 두고 입력되며, 이 수들은 모두 1 이상 10,000 이하이다. www.acmicpc.net #include using namespace std; #define ll long long int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; int arr[20001]; for(int i=0; i> arr[i]; } sort(arr, arr+N); if(N%2 == 0) //중앙값이 2개인 경우 {..
문제링크 : https://www.acmicpc.net/problem/4307 4307번: 개미 개미 여러 마리가 길이가 lcm인 막대 위에 있다. 각 개미의 이동 속도는 모두 일정하며, 1cm/s이다. 개미가 막대의 마지막까지 걸어간다면, 개미는 그 즉시 떨어지게 된다. 또, 두 개미가 만나게 된 www.acmicpc.net #include using namespace std; #define ll long long int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int T, L, N; cin >> T; while(T--) { cin >> L >> N; int MIN_result = 0, MAX_result = 0; int mid = L/2..
문제링크 : https://www.acmicpc.net/problem/6588 6588번: 골드바흐의 추측 각 테스트 케이스에 대해서, n = a + b 형태로 출력한다. 이때, a와 b는 홀수 소수이다. 숫자와 연산자는 공백 하나로 구분되어져 있다. 만약, n을 만들 수 있는 방법이 여러 가지라면, b-a가 가장 큰 www.acmicpc.net #include using namespace std; #define fastio ios_base::sync_with_stdio(0); cin.tie(0); #define ll long long int arr[1000001]; void makePrime() { for(int i=2; i*i n; if(n==0) break; bool check = false; fo..
문제링크 : https://www.acmicpc.net/problem/6591 6591번: 이항 쇼다운 각 테스트 케이스에 대해서, 정답을 출력한다. 항상 정답이 231보다 작은 경우만 입력으로 주어진다. www.acmicpc.net #include using namespace std; #define ll long long int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; while(1) { cin >> N >> K; if(N==0 && K==0) break; ll result = 1; int num = min(K, N-K); //K!, (N-K)! for(int i=1; i
문제링크 : https://www.acmicpc.net/problem/14235 14235번: 크리스마스 선물 크리스마스에는 산타가 착한 아이들에게 선물을 나눠준다. 올해도 산타는 선물을 나눠주기 위해 많은 노력을 하고 있는데, 전세계를 돌아댕기며 착한 아이들에게 선물을 나눠줄 것이다. 하지만 www.acmicpc.net #include using namespace std; #define ll long long int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int N, A, present; priority_queuepq; cin >> N; while(N--) { cin >> A; if(A==0) { if(pq.empty()) { cout
문제링크 : https://www.acmicpc.net/problem/9324 9324번: 진짜 메시지 스파이들은 사령부와 통신하기 위해서 SMTP(비밀 메시지 전송 프로토콜)를 사용해 비밀 회선으로 전자 메시지를 보낸다. 메시지가 적들에 의해 조작되어 보내진 것이 아닌 진짜 메시지라는 것 www.acmicpc.net #include using namespace std; #define ll long long int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int check[26]; int T; cin >> T; while(T--) { memset(check, 0, sizeof(check)); string result=""; string M;..
문제링크 : https://www.acmicpc.net/problem/14731 14731번: 謎紛芥索紀 (Large) 성민이는 이번 학기에 미적분학 과목을 수강하고 있다. 다항함수의 미분 단원 과제를 하던 도중 미분을 하기가 귀찮아진 성민이는 미분하려는 함수 f(x)가 주어지면, 미분 된 함수 f’(x)를 자동 www.acmicpc.net #include using namespace std; #define ll long long #define MOD 1000000007 ll cal(ll a) { if(a==0) return 1; ll half = cal(a/2); //반으로 나눠주기 if(a%2==1) return (half * half * 2) % MOD; return (half * half) % M..
#include using namespace std; #define ll long long int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; queue q; while(N) { q.push(N%2); //이진수 저장 N/=2; } ll result = 0; ll multiply = 1; while(!q.empty()) { result += q.front() * multiply; multiply *= 3; //3진수 만들기 q.pop(); } cout 2**0 + 2**2 3진수 : 1 0 1 -> 3**0 + 3**2
문제링크 : https://www.acmicpc.net/problem/11123 11123번: 양 한마리... 양 두마리... 얼마전에 나는 불면증에 시달렸지... 천장이 뚫어져라 뜬 눈으로 밤을 지새우곤 했었지. 그러던 어느 날 내 친구 광민이에게 나의 불면증에 대해 말했더니 이렇게 말하더군. "양이라도 세봐!" www.acmicpc.net #include using namespace std; queueq; bool check[101][101]; char c[101][101]; int H, W; int dx[] = { -1,1,0,0 }; int dy[] = { 0,0,-1,1 }; void bfs(int x, int y) { check[x][y] = 1; //양이므로 방문 처리 q.push({ x,y..
문제의 합 : https://www.acmicpc.net/problem/3273 3273번: 두 수의 합 n개의 서로 다른 양의 정수 a1, a2, ..., an으로 이루어진 수열이 있다. ai의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, ai + aj = x (1 ≤ i > n; for(int i=0; i> num; arr.push_back(num); } cin >> x; sort(arr.begin(), arr.end()); int l=..
문제링크 : https://www.acmicpc.net/problem/7511 7511번: 소셜 네트워킹 어플리케이션 각 테스트 케이스마다 "Scenario i:"를 출력한다. i는 테스트 케이스 번호이며, 1부터 시작한다. 그 다음, 각각의 쌍마다 두 사람을 연결하는 경로가 있으면 1, 없으면 0을 출력한다. 각 테스트 케이스 www.acmicpc.net #include using namespace std; int parent[100001]; int find_root(int x) { if(x == parent[x]) return x; //루트노드면 그대로 반환 return find_root(parent[x]); //자식노드면 부모노드로 다시 탐색 } void Union(int a, int b) { a ..
문제링크 : https://www.acmicpc.net/problem/11332 11332번: 시간초과 각 테스트 케이스들에 대하여 시간 초과가 나면 "TLE!", 시간 초과가 나지 않으면 "May Pass." 를 출력한다. www.acmicpc.net #include using namespace std; #define LL long long #define MAX 100000000 int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int C; LL N, T, L; string S; cin >> C; while(C--) { cin >> S >> N >> T >> L; if(S == "O(N)") { if(N*T