문제링크 : https://www.acmicpc.net/problem/11068#include using namespace std;const int MOD = 1000000007;bool isPanlindrome(int n){ for(int i=2; i> T; while(T--) { int N; cin >> N; if(isPanlindrome(N)) cout 입력받은 수에 대해서 2~64까지 각각의 진법으로 변환하여 계산하여 문자열에 저장하고,해당 문자열을 뒤집은 문자열과 비교해 같은가 아닌가를 체크한다. 같다면 1을 아니면 0을 출력해주면 된다.
#include #include #include #include #include using namespace std;bool visited[501][501];int dy[] = {1, -1, 0, 0};int dx[] = {0, 0, 1, -1};int N, M;void bfs(int y, int x, int& cnt, set& s, vector>& v){ queue> q; q.push({y, x}); visited[y][x] = true; cnt = 1; s.insert(x); while(!q.empty()) { auto [yy, xx] = q.front(); q.pop(); for(int i=0; i= N..
#include #include #include using namespace std;int solution(vector> targets) { int answer = 0; sort(targets.begin(), targets.end()); int i = 0; while (i 최소값을 찾기 위해 가장 많이 겹치는 구간을 찾아야 한다.따라서 우선 오름차순 정렬을 해주고, end 값을 기준으로 값을 체크할 필요가 있다. 현재 end 값을 기준으로, 다음 값의 start 값을 체크한다.만약 start가 end보다 작다면, 두 값은 겹치는 범위에 해당하므로 추가 미사일이 필요 없을 것이다.해당 start의 end 값이 직전 end 값보다 작다면 end 값을 새로 갱신하여 가장 좁은 공..
#include #include using namespace std;bool check(vectorboard, char c){ if(board[0][0] == c && board[1][1] == c && board[2][2] == c) return 1; //대각선 체크 if(board[0][2] == c && board[1][1] == c && board[2][0] == c) return 1; for(int i=0; i board) { int answer = 1; int oCnt = 0, xCnt = 0; for(auto i : board) { for(int j=0; j= 2) answer = 0; if(oWin && xWin) ans..

#include #include #include using namespace std;long long solution(int r1, int r2) { long long answer = 0; for(int i=1; i 원의 방정식을 응용한 문제다.먼저 원의 방정식은 다음과 같다. 이를 응용하여 내부 원의 반지름 r1과 외부 원의 반지름 r2를 참고하면 다음과 같은 식이 성립한다. 위 식을 토대로 계산하면 또 다음과 같음을 알 수 있다. 따라서 x축을 고정시켜놓고, 위 공식을 통해 최소 Y값, 최대 Y값을 구해주면 된다.그리고 가능한 정수 값을 찾는 것이기에 최소의 경우 올림처리를, 최대의 경우 내림처리를 해서 맞춰주어야한다.추가로 주의할 점은 x 이 경우에 이후 계산식이 무조건 음수로 s..
#include #include using namespace std;int answer = 0;int arr[13];bool check(int n){ for(int i=0; i 퀸의 경우 가로세로 또는 대각선으로 이동이 가능하다.따라서 위 3가지 방향에 대해 고려를 해야한다. 우선 행을 고정시키고, 여기서 열만 바꿔서 퀸을 배치시킬 것이다.해당 값을 토대로 행을 옮겨 놓을 예정인 값의 유효여부를 판단하고, 가능하면 이어서 dfs 탐색을 이어나간다. 행을 고정시켰기에, 행을 탐색할 필요는 없다.따라서 남은건 같은 열인지, 또는 대각선인지 체크하는 것이다.반복문을 통해 놓을 예정인 위치가 이미 값이 존재하는 지 여부를 통해 열을 체크한다.대각선의 경우 행의 차이와 열의 차이가 같은 지 계산식을 통해 대..
#include #include #include #include using namespace std;bool visited[51][51];int dy[] = {0, 0, -1, 1};int dx[] = {1, -1, 0, 0};void Lift(char target, vector& storage, int n, int m){ vector> del; memset(visited, false, sizeof(visited)); for(int i=0; i>q; q.push({i, j}); visited[i][j]=1; while(!q.empty()) { ..
문제링크 : https://www.acmicpc.net/problem/2705#include using namespace std;const int MOD = 1000000007;int dp[1001];int cal(int n){ if(n> T; memset(dp, -1, sizeof(dp)); while(T--) { cin >> N; cout 주어진 파티션에 대해 왼쪽 절반과 오른쪽 절반이 재귀적인 팰린드롬인지 체크해야한다.따라서 입력받은 n을 기준으로 절반만 체크하며 절반에 가능한 값이 있으면 대칭으로 사용이 가능하기에 가능한 가짓수를 더한다. 재귀 과정에서 시간초과 방지를 위해 이미 값이 존재하면 바로 반환해주도록 한다.그리고 기본적으로 dp[n]=1을..
문제링크 : https://www.acmicpc.net/problem/28069#include using namespace std;const int MOD = 1000000007;int main() { int N, K; cin >> N >> K; vectordp(N+1, INT_MAX); dp[0]=0; for(int i=0; i 이동 방법은 문제에 주어진 것처럼 2가지이다.(계단 한 칸 이동 or i+i/2 번째 계단으로 순간이동)따라서 해당 행동을 토대로 dp 식을 구성해준다. 먼저 dp는 최대값으로 초기화하고, 최소값을 통해 값을 갱신해나간다.이때 i+1과 i+i/2의 값이 N이 초과하지 않도록 범위를 제한해주어야 한다.둘 다 행동이 하나이므로 dp[i]+1과 비교하게 되..
문제링크 : https://www.acmicpc.net/problem/12849#include using namespace std;const int MOD = 1000000007;long long dp[8], arr[8];//정보, 전산, 신양, 진리, 학생, 형남, 환경, 미래int main() { int D; cin >> D; dp[0] = 1; // 정보과학관에서 시작 while (D--) { arr[0] = dp[1] + dp[7]; // 정보 - 전산, 미래 arr[1] = dp[0] + dp[2] + dp[7]; // 전산 - 정보, 신양, 미래 arr[2] = dp[1] + dp[3] + dp[6] + dp[7]..
문제링크 : https://www.acmicpc.net/problem/10422#include using namespace std;typedef long long ll;#define MOD 1000000007long long arr[5001];int main() { ios::sync_with_stdio(false); cin.tie(NULL); int T, N; cin >> T; arr[0]=1; //빈 문자열 for(int i=2; i> N; cout 우선 올바른 괄호 문자열은 특성상 짝수만 가능하다.그리고 구역을 2개 나눠서 생각할 필요가 있다.일단 간단하게 초기값을 알아보면 다음과 같다.N = 2()N = 4()(), (()) N = 4인 케이스를 보면,..
#include #include #include #include using namespace std;int getTime(string time){ return stoi(time.substr(0, 2)) * 60 + stoi(time.substr(3, 2));}bool cmp(vectora, vectorb){ return a[1] solution(vector> plans) { vector answer; stack>pause; sort(plans.begin(), plans.end(), cmp); for(int i=0; i=playtime) { answer.push_back(name); //과제 수행 rema..
#include #include using namespace std;int arr[4] = {10, 20, 30, 40};vectorv;int sign, price; //가입자 및 금액void dfs(vector> users, vector emoticons){ if(v.size()==emoticons.size()) //할인율 모두 결정 { int tmp_sign = 0; int tmp_price = 0; for(int i=0; i= users[i][1]) tmp_sign++; //구매 금액이 일정량 이상이면 이모티콘 가입 else tmp_price+=tmp; //아니면 매출액에 저장 } if (tm..
#include #include #include using namespace std;int solution(vector> relation) { int answer = 0; int row = relation.size(); //튜플 int col = relation[0].size(); //속성 vectorv; for(int i=1; is; for(int j=0; j 비트마스킹을 또한 조합 생성으로 풀 수 있는 문제이다.먼저 속성의 조합 경우의 수를 따져야한다.예제의 케이스를 보면 학번, 이름, 전공, 학년 4가지에 대해서의 조합이므로 2^4로 총 16가지이다.이를 비트마스킹으로 표현하면 1따라서 첫 반복문의 i는 학번, 이름, 전공, 학년의..