#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
string ball = "0123";
int N;
 
void swap(int cup1, int cup2)
{
    int cup1Idx, cup2Idx;
    
    for(int i = 1; i <= 3; i++)
    {
        if(ball[i] == (char)(cup1+'0'))
        {
            cup1Idx = i;
        }
        else if(ball[i] == (char)(cup2+'0'))
        {
            cup2Idx = i;
        }
    }
    
    char temp = ball[cup1Idx];
    ball[cup1Idx] = ball[cup2Idx];
    ball[cup2Idx] = temp;
}
    
int main(void)
{
//    freopen("B1547_input.txt", "r", stdin);
    
    cin >> N; 
    
    for(int i = 1; i <= N; i++)
    {
        int cup1, cup2;
        cin >> cup1 >> cup2;
        
        swap(cup1, cup2);
    }
    
    cout << ball[1];
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int N;
string command;
char map[110][110];
int dir = 2// 북(0) 동(1) 남(2) 서(3) 
 
void execute(int &x, int &y, char command)
{
    if(command == 'R')
    {
        dir = (dir+1) % 4;
    }
    else if(command == 'L')
    {
        dir = (dir+3) % 4;
    } 
    else if(command == 'F')
    {
        if(dir == 0)
        {
            x -= 1;
        }
        else if(dir == 1)
        {
            y += 1;
        }
        else if(dir == 2)
        {
            x += 1;
        }
        else if(dir == 3)
        {
            y -= 1;
        }
        
        map[x][y] = '.';
    }
}
 
int main(void)
{
//    freopen("B1062_input.txt", "r", stdin);
    
    cin >> N >> command;
    
    for(int i = 0; i < 110; i++)
    {
        for(int j = 0; j < 110; j++)
        {
            map[i][j] = '#';
        }
    }
    
    // 초기값 55, 55를 잡으면 맵의 크기가 110이기때문에 상하좌우 한 방향으로 50칸을 가더라도 범위안에서 해결 가능 
    int x = 55;
    int y = 55
    map[x][y] = '.';
    
    for(int i = 0; i < N; i++)
    {
        execute(x, y, command[i]);
    }
    
    // 미로의 왼쪽위, 오른쪽아래 양끝점 구하기 
    int leftX = 55, leftY = 55, rightX = 55, rightY = 55;
    
    for(int i = 0; i < 110; i++)
    {
        for(int j = 0; j < 110; j++)
        {
            if(map[i][j] == '.')
            {
                if(leftX > i)
                {
                    leftX = i;
                }
                
                if(leftY > j)
                {
                    leftY = j;
                }
                
                if(rightX < i)
                {
                    rightX = i;
                }
                
                if(rightY < j)
                {
                    rightY = j;
                }
            }
        }
    }
    
    for(int i = leftX; i <= rightX; i++)
    {
        for(int j = leftY; j <= rightY; j++)
        {
            cout << map[i][j];
        }
        cout << endl;
    }
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
 
int N, K;
string word[55];
int alphabet[26];
int Max;
 
int count()
{
    int wordCnt = 0;
    
    for(int i = 1; i <= N; i++)
    {
        bool flag = true;
        
        for(int j = 0; j < word[i].size(); j++)
        {
            if(alphabet[word[i][j]-'a'== 0)
            {
                flag = false;
                break;
            }
        }
        
        if(flag == true)
        {
            wordCnt++;        
        }
    }
    
    return wordCnt;
}
 
void combination(int idx, int cnt)
{
    if(cnt == K-5)
    {
        Max = max(Max, count());
        
        return;
    }
    
    for(int i = idx; i < 26; i++)
    {
        if(alphabet[i] == 1)
        {
            continue;
        }
        
        alphabet[i] = 1;
        combination(i+1, cnt+1);
        alphabet[i] = 0;
    }
}
 
int main(void)
{
//    freopen("B1062_input.txt", "r", stdin);
    
    cin >> N >> K;
    
    if(K <= 4)
    {
        for(int i = 1; i <= N; i++)
        {
            cin >> word[i];
        }
        
        cout << "0";
    }
    else
    {
        alphabet['a'-'a'= 1;
        alphabet['c'-'a'= 1;
        alphabet['i'-'a'= 1;
        alphabet['n'-'a'= 1;
        alphabet['t'-'a'= 1;
        
        for(int i = 1; i <= N; i++)
        {
            cin >> word[i];
        }    
        
        combination(00);
        
        cout << Max;
    }
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
 
int row, col;
char map[55][55];
int Min = 99999999;
 
int main(void)
{
//    freopen("B1018_input.txt", "r", stdin);
    
    cin >> row >> col;
    
    for(int i = 0; i < row; i++)
    {
        string input;
        cin >> input;
        
        for(int j = 0; j < col; j++)
        {
            map[i][j] = input[j];
        }
    }
    
    for(int i = 0; i+7 < row; i++)
    {
        for(int j = 0; j+7 < col; j++)
        {
            for(int cnt = 0; cnt < 2; cnt++)
            {
                // 칠해야하는 정사각형의 갯수 
                int paint = 0;
                
                // 왼쪽 위가 B 
                if(cnt == 0)
                {
                    // 행, 열의 첫번째 색깔 저장 
                    char row_paint = 'B';
                    char col_paint = 'B';
                    
                    for(int k = i; k < i+8; k++)
                    {
                        for(int m = j; m < j+8; m++)
                        {
                            if(map[k][m] != col_paint)
                            {
                                paint++;
                            }
                            
                            // 열이 바뀔떄마다 색깔 변경 
                            if(col_paint == 'B')
                            {
                                col_paint = 'W'
                            }
                            else
                            {
                                col_paint = 'B';
                            }
                        }
                        
                        // 행이 바뀔때마다 색깔 변경 
                        if(row_paint == 'B')
                        {
                            row_paint = 'W';
                            col_paint = 'W';
                        }
                        else
                        {
                            row_paint = 'B';
                            col_paint = 'B';
                        }
                    }    
                }    
                // 왼쪽 위가 W
                else
                {
                    // 행, 열의 첫번째 색깔 저장 
                    char row_paint = 'W';
                    char col_paint = 'W';
                    
                    for(int k = i; k < i+8; k++)
                    {
                        for(int m = j; m < j+8; m++)
                        {
                            if(map[k][m] != col_paint)
                            {
                                paint++;
                            }
                            
                            if(col_paint == 'B')
                            {
                                col_paint = 'W';
                            }
                            else
                            {
                                col_paint = 'B';
                            }
                        }
                        
                        if(row_paint == 'B')
                        {
                            row_paint = 'W';
                            col_paint = 'W';
                        }
                        else
                        {
                            row_paint = 'B';
                            col_paint = 'B';
                        }
                    }    
                }
                
                Min = min(Min, paint);
            }
        }
    }
    
    cout << Min;
    
    return 0;
}
cs
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
 
string word;
int dp[2510][2510];
int minResult[2510];
 
int solve(int s, int e)
{
    if(s >= e)
    {
        return 1;
    }
    
    if(dp[s][e] != -1)
    {
        return dp[s][e];
    }
    
    dp[s][e] = 0;
    
    if(word[s] == word[e])
    {
        dp[s][e] = solve(s+1, e-1);
    }
    
    return dp[s][e];
}
 
int main(void)
{
//    freopen("B1509_input.txt", "r", stdin);
    
    cin >> word;
    word = "0" + word;
    
    memset(dp, -1sizeof(dp));
    
    minResult[0= 0;
    for(int i = 1; i < word.size(); i++)
    {
        minResult[i] = 99999999;
        
        for(int j = 1; j <= i; j++)
        {
            if(solve(j, i) == 1)
            {
                minResult[i] = min(minResult[i], minResult[j-1+ 1);
            }
        }
    }    
    
    cout << minResult[word.size()-1];
    
    return 0;
}
cs

1.

#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
 
int N, M;
int arr[2010];
int dp[2010][2010]; // [시작][끝] 
 
int solve(int s, int e)
{
    if(s >= e)
    {
        return 1;
    }
    
    if(dp[s][e] != -1)
    {
        return dp[s][e];
    }
    
    dp[s][e] = 0;
    
    if(arr[s] == arr[e])
    {
        dp[s][e] = solve(s+1, e-1);    
    }
    
    return dp[s][e];
}
 
int main(void)
{
//    freopen("B10942_input.txt", "r", stdin);
    
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    
    cin >> N;
    
    for(int i = 1; i <= N; i++)
    {
        cin >> arr[i];
    }
    memset(dp, -1sizeof(dp));
    
    cin >> M;
    
    for(int i = 1; i <= M; i++)
    {
        int s, e;
        cin >> s >> e;
        
        cout << solve(s, e) << "\n";
    }
 
    return 0;
}
cs

 

2.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int N, M;
int arr[2010];
int dp[2010][2010]; // [시작][끝] 
 
int main(void)
{
//    freopen("B10942_input.txt", "r", stdin);
    
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    
    cin >> N;
    
    for(int i = 1; i <= N; i++)
    {
        cin >> arr[i];
    }
    
    // 길이 1
    for(int i = 1; i <= N; i++)
    {
        dp[i][i] = 1;    
    } 
    
    // 길이 2
    for(int i = 1; i <= N-1; i++)
    {
        if(arr[i] == arr[i+1])
        {
            dp[i][i+1= 1;
        }    
    } 
    
    // 길이 3이상
    for(int k = 3; k <= N; k++)
    {
        for(int i = 1; i <= N-k+1; i++)
        {
            int j = i+k-1;
            
            if(arr[i] == arr[j] && dp[i+1][j-1== 1)
            {
                dp[i][j] = 1;
            }
        }
    }
    
    cin >> M;
    
    for(int i = 1; i <= M; i++)
    {
        int s, e;
        cin >> s >> e;
        
        cout << dp[s][e] << "\n";
    }
 
    return 0;
}
cs
#include <iostream>
#include <algorithm>
using namespace std;
 
int row, col;
int map[1010][1010];
int dp[1010][1010];
 
int dx[3= {101}; 
int dy[3= {011};  
 
int safe(int x, int y)
{
    if(x >= 0 && y >= 0 && x < row && y < col)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
 
int DFS(int x, int y)
{
    if(x == row-1 && y == col-1)
    {
        return map[x][y];
    }
    
    if(dp[x][y] != -1)
    {
        return dp[x][y];
    }
    
    for(int i = 0; i < 3; i++)
    {
        int xpos = x + dx[i];
        int ypos = y + dy[i];
            
        if(safe(xpos, ypos) == 1)
        {
            dp[x][y] = max(dp[x][y], DFS(xpos, ypos) + map[x][y]);
        }
    }
    
    return dp[x][y];
}
 
int main(void)
{
//    freopen("B11048_input.txt", "r", stdin);
    
    cin >> row >> col;
    
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < col; j++)
        {
            cin >> map[i][j];
            dp[i][j] = -1;
        }
    }
    
    cout << DFS(00);
    
    return 0;
}
cs
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
 
int E, S, M;
int e = 1;
int s = 1;
int m = 1;
int year = 1;
 
int main(void)
{
//    freopen("B1476_input.txt", "r", stdin);
    
    cin >> E >> S >> M;
    
    while(1)
    {    
        if(e > 15)
        {
            e = 1;
        }
        
        if(s > 28)
        {
            s = 1;
        }
        
        if(m > 19)
        {
            m = 1;
        }
        
        if(E == e && S == s && M == m)
        {
            cout << year;
            break;
        }
        
        e++;
        s++;
        m++;
        year++;
    }
    
    return 0;
}
cs

+ Recent posts