#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int N;
int map[300][300];
int square;
 
int dx[4= {10-10};
int dy[4= {0-101};
 
int main(void)
{
//    freopen("B15685_input.txt", "r", stdin);
    
    cin >> N;
    
    for(int k = 1; k <= N; k++)
    {
        int x, y, d, gen;
        
        cin >> x >> y >> d >> gen;
        
        x += 150;
        y += 150;
        map[x][y] = k;
        
        vector<int> dir;
        dir.push_back(d);
        
        for(int i = 1; i <= gen; i++)
        {
            vector<int> tempDir;
            
            for(int j = dir.size()-1; j >= 0; j--)
            {
                tempDir.push_back((dir[j]+1) % 4);
            }
            
            for(int j = 0; j < tempDir.size(); j++)
            {
                dir.push_back(tempDir[j]);
            }
        }
        
        for(int i = 0; i < dir.size(); i++)
        {
            x += dx[dir[i]];
            y += dy[dir[i]];
            
            map[x][y] = k;
        }
    }
    
    for(int i = 0; i < 300; i++)
    {
        for(int j = 0; j < 300; j++)
        {
            int cnt = 0;
            
            for(int m = i; m < i+2; m++)
            {
                for(int n = j; n < j+2; n++)
                {
                    if(map[m][n] != 0)
                    {
                        cnt++;            
                    }
                }
            }
            
            if(cnt == 4)
            {
                square++;
            }
        }
    }
    
    cout << square;
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int N, L;
int map[110][110];
int ans;
 
void Rotate()
{
    int temp[110][110];
    
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            temp[i][j] = map[i][j];
        }
    }
    
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            map[i][j] = temp[N-1-j][i];
        }
    }
}
 
int main(void)
{
//    freopen("B14890_input.txt", "r", stdin);
    
    cin >> N >> L;
    
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            cin >> map[i][j];  
        }
    }
    
    for(int i = 0; i < N; i++)
    {
        int up = 0;
        
        for(int j = 0; j < N-1; j++)
        {                
            // 내리막 
            if(map[i][j]-map[i][j+1== 1)
            {
                int std = map[i][j];
                int cnt = 0;
                
                for(int k = j+1; k <= j+&& k < N; k++)
                {
                    if(std-1 == map[i][k])
                    {
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                
                if(cnt != L)
                {
                    break;
                }
                else
                {
                    j += (L-1);
                    up = j+2;
                }
            }
            // 오르막 
            else if(map[i][j]-map[i][j+1== -1)
            {
                int std = map[i][j+1]; 
                int cnt = 0;
 
                for(int k = j; k > j-&& k >= up; k--)
                {
                    if(std-1 == map[i][k])
                    {
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                
                if(cnt != L)
                {
                    break;
                }
            }
            // 평지 
            else if(map[i][j]-map[i][j+1== 0)
            {
                // pass
            }
            else
            {
                break;
            }    
    
            if(j >= N-2)
            {
                ans++;
                break;
            }
        }
    }
    
    // 왼쪽 90도 회전 
    Rotate();
    
    for(int i = 0; i < N; i++)
    {
        int up = 0;
        
        for(int j = 0; j < N-1; j++)
        {                
            // 내리막 
            if(map[i][j]-map[i][j+1== 1)
            {
                int std = map[i][j];
                int cnt = 0;
                
                for(int k = j+1; k <= j+&& k < N; k++)
                {
                    if(std-1 == map[i][k])
                    {
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                
                if(cnt != L)
                {
                    break;
                }
                else
                {
                    j += (L-1);
                    up = j+2;
                }
            }
            // 오르막 
            else if(map[i][j]-map[i][j+1== -1)
            {
                int std = map[i][j+1]; 
                int cnt = 0;
 
                for(int k = j; k > j-&& k >= up; k--)
                {
                    if(std-1 == map[i][k])
                    {
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                
                if(cnt != L)
                {
                    break;
                }
            }
            // 평지 
            else if(map[i][j]-map[i][j+1== 0)
            {
                // pass
            }
            else
            {
                break;
            }    
    
            if(j >= N-2)
            {
                ans++;
                break;
            }
        }
    }
    
    cout << ans;
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
 
int row, col;
int map[55][55];
int visited[55][55];
int x, y, dir;
int cleanCnt;
 
int dx[4= {-1010}; // 북 동 남 서 
int dy[4= {010-1}; // 북 동 남 서
 
int main(void)
{
//    freopen("B14503_input.txt", "r", stdin);
    
    cin >> row >> col;
    
    cin >> x >> y >> dir;
    
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < col; j++)
        {
            cin >> map[i][j];
        }
    }
    
    bool clean = true;
    int all_cleanCnt = 0;
    while(1)
    {    
        // c. 네 방향 모두 청소가 이미 되어있거나 벽인 경우에는
        if(all_cleanCnt == 4)
        {
            all_cleanCnt = 0;
            
            int nDir = (dir+2) % 4;
            int nx = x+dx[nDir];
            int ny = y+dy[nDir];
            
            // d. 뒤쪽 방향이 벽이라 후진도 할 수 없는 경우에는 작동을 멈춘다.
            if(map[nx][ny] == 1)
            {
                break;
            }
            // c. 바라보는 방향을 유지한 채로 한 칸 후진을 하고 2번으로 돌아간다.
            else
            {
                x = nx;
                y = ny;
                
                continue;
            }    
        }
        
        // 1. 현재 위치를 청소한다.    
        if(clean)
        {
            all_cleanCnt = 0;
            
            visited[x][y] = 1;
            cleanCnt++;
            clean = false;
        }
        
        // 2. 현재 위치에서 현재 방향을 기준으로 왼쪽방향부터
        int tempDir = (dir+3) % 4;
        int xpos = x+dx[tempDir];
        int ypos = y+dy[tempDir];
        
        // a. 왼쪽 방향에 아직 청소하지 않은 공간이 존재한다면, 그 방향으로 회전한 다음 한 칸을 전진하고 1번부터 진행한다.
        if(visited[xpos][ypos] == 0 && map[xpos][ypos] == 0)
        {
            dir = tempDir;
            x = xpos;
            y = ypos;
            clean = true;
            
            continue;
        }
        
        // b. 왼쪽 방향에 청소할 공간이 없다면, 그 방향으로 회전하고 2번으로 돌아간다.
        if(visited[xpos][ypos] == 1 || map[xpos][ypos] == 1)
        {            
            all_cleanCnt++;
            
            dir = tempDir;
            continue;
        }    
    }
    
    cout << cleanCnt;
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
 
int row, col;
int map[25][25];
int dice[7];
int diceX, diceY;
int commandNum;
 
int dx[5= {000-11}; // 동 서 북 남
int dy[5= {01-100}; // 동 서 북 남  
 
int safe(int x, int y)
{
    if(x >= 0 && y >= 0 && x < row && y < col)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
 
void changeDice(int command)
{
    int temp[7];
    for(int i = 1; i <= 6; i++)
    {
        temp[i] = dice[i];
    }
    
    if(command == 1)
    {
        dice[1= temp[4];
        dice[3= temp[1];
        dice[4= temp[6];
        dice[6= temp[3];
    }
    else if(command == 2)
    {
        dice[1= temp[3];
        dice[3= temp[6];
        dice[4= temp[1];
        dice[6= temp[4];
    }
    else if(command == 3)
    {
        dice[1= temp[5];
        dice[2= temp[1];
        dice[5= temp[6];
        dice[6= temp[2];
    }
    else if(command == 4)
    {
        dice[1= temp[2];
        dice[2= temp[6];
        dice[5= temp[1];
        dice[6= temp[5];
    }    
}
 
int main(void)
{
//    freopen("B14499_input.txt", "r", stdin);
    
    cin >> row >> col >> diceX >> diceY >> commandNum;
    
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < col; j++)
        {
            cin >> map[i][j];
        }
    }
    
    for(int i = 1; i <= commandNum; i++)
    {
        int command;
        cin >> command;
        
        diceX += dx[command];
        diceY += dy[command];
        
        if(safe(diceX, diceY) == 0)
        {
            diceX -= dx[command];
            diceY -= dy[command];
            continue;
        }
        
        changeDice(command);
        
        // 주사위를 굴렸을 때, 이동한 칸에 쓰여 있는 수가 0이면, 주사위의 바닥면에 쓰여 있는 수가 칸에 복사된다.
        if(map[diceX][diceY] == 0)
        {
            map[diceX][diceY] = dice[6];
        }
        // 0이 아닌 경우에는 칸에 쓰여 있는 수가 주사위의 바닥면으로 복사되며, 칸에 쓰여 있는 수는 0이 된다.
        else
        {
            dice[6= map[diceX][diceY];
            map[diceX][diceY] = 0;    
        }
        
        cout << dice[1<< "\n";
    }
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
 
int N, M;
int board[1010];
int dice[1010];
 
int main(void)
{
//    freopen("B5566_input.txt", "r", stdin);
    
    cin >> N >> M;
    
    for(int i = 1; i <= N; i++)
    {
        cin >> board[i];
    }
    
    for(int i = 1; i <= M; i++)
    {
        cin >> dice[i];
    }
    
    int now = 1;
    int diceIdx = 1;
    int diceCnt = 0;
    while(1)
    {
        if(now >= N)
        {
            break;
        }
        
        now += dice[diceIdx];
        now += board[now];
        
        diceCnt++;
        diceIdx++;    
    }
    
    cout << diceCnt;
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
 
int N, M;
int board[1010];
int dice[1010];
 
int main(void)
{
//    freopen("B5566_input.txt", "r", stdin);
    
    cin >> N >> M;
    
    for(int i = 1; i <= N; i++)
    {
        cin >> board[i];
    }
    
    for(int i = 1; i <= M; i++)
    {
        cin >> dice[i];
    }
    
    int now = 1;
    int diceIdx = 1;
    int diceCnt = 0;
    while(1)
    {
        if(now >= N)
        {
            break;
        }
        
        now += dice[diceIdx];
        now += board[now];
        
        diceCnt++;
        diceIdx++;    
    }
    
    cout << diceCnt;
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
 
int N;
int num[250000];
 
void eratos(int N)
{
    for(int i = 2; i <= N; i++)
    {
        if(num[i] == 1)
        {
            continue;
        }
        
        for(int j = i+i; j <= N; j += i)
        {
            num[j] = 1;
        }
    }
}
 
int main(void)
{
//    freopen("B4948_input.txt", "r", stdin);
    
    num[1= 1;
    eratos(250000);
    
    while(cin >> N)
    {
        int cnt = 0;
        
        if(N == 0)
        {
            break;
        }
        
        for(int i = N+1; i <= N+N; i++)
        {
            if(num[i] == 0)
            {
                cnt++;
            }
        }
        
        cout << cnt << "\n";
    }
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
 
int N;
int appleNum;
int rotateNum;
int rotateIdx;
int time;
 
vector<pair<intint>> apple;
vector<pair<intchar>> rotate;
deque<pair<intint>> snake;;
 
int dx[4= {-1010}; // 북, 동, 남, 서 
int dy[4= {010-1}; // 북, 동, 남, 서 
 
int safe(int x, int y)
{
    if(x >= 1 && y >= 1 && x <= N && y <= N)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
 
int check_snake(int x, int y)
{
    for(int i = 0; i < snake.size(); i++)
    {
        if(x == snake[i].first && y == snake[i].second)
        {
            return 0;
        }
    }
    
    return 1;
 
void solve(int x, int y, int dir)
{    
    while(1)
    {
        // 시간 증가 
        time++
        
        // 뱀의 머리 좌표 
        x += dx[dir];
        y += dy[dir];
        
        if(safe(x, y) == 1 && check_snake(x, y) == 1)
        {         
            // 몸길이 증가
            snake.push_front({x, y});
        
            // 사과 체크 
            bool eat_apple = false;
            
            for(int i = 0; i < apple.size(); i++)
            {
                if(x == apple[i].first && y == apple[i].second)
                { 
                    eat_apple = true;
                    apple.erase(apple.begin()+i);
                    break;        
                }
            }
            
            // 사과 못먹었으면 몸길이 감소(꼬리 자름) 
            if(eat_apple == false)
            {
                snake.pop_back();
            }
        }
        // 벽에 닿거나 자신의 몸에 닿으면 게임종료 
        else
        {
            return;
        }
        
        // 방향 전환 
        if(time == rotate[rotateIdx].first)
        {
            // 왼쪽 90도 
            if(rotate[rotateIdx].second == 'L')
            {
                dir = (dir+3) % 4;
            }
            // 오른쪽 90도 
            else
            {
                dir = (dir+1) % 4;
            }
            
            rotateIdx++;
        }    
    }
}
 
int main(void)
{
//    freopen("B3190_input.txt", "r", stdin);
    
    cin >> N;
    
    cin >> appleNum; 
    for(int i = 0; i < appleNum; i++)
    {
        int x, y;
        cin >> x >> y;
        
        apple.push_back({x, y});
    }
    
    cin >> rotateNum;
    for(int i = 0; i < rotateNum; i++)
    {
        int time;
        char dir;
        cin >> time >> dir;
        
        rotate.push_back({time, dir});
    }
    
    snake.push_back({11});
    solve(111);
    
    cout << time; 
    
    return 0;
}
cs

+ Recent posts