GameChoi
Choi Programming
GameChoi
전체 방문자
오늘
어제
  • 분류 전체보기 (468)
    • C++ Algorithm & Study (184)
      • C++ & Algorithm Strategies (45)
      • Game Math & DirectX 11 (72)
      • Server + UE5 (29)
      • Lyra Clone Coding (37)
    • Create Game (284)
      • [Window API] Game Client & .. (55)
      • [DirectX] DirectX 2D & 3D (155)
      • [UE5] BLUEPRINT & C++ (74)
    • odds and ends (0)
      • English (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Algorithm Strategies
  • Player Move Packet
  • GAME Client
  • Game Room
  • core
  • RPG Game
  • Network Worker
  • server
  • job queue
  • Direct3D
  • Other Character
  • c++
  • Player State
  • Game Server
  • Destination Move Packet
  • protobuf
  • UE5
  • session
  • Direct11
  • client

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
GameChoi

Choi Programming

[Programmers] 카펫
C++ Algorithm & Study/C++ & Algorithm Strategies

[Programmers] 카펫

2023. 1. 21. 17:11

 

https://school.programmers.co.kr/learn/courses/30/lessons/42842

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

0. Headers

#include <vector>
using namespace std;

1. 알고리즘

1.1 First Algorithm

 - 가로, 세로에서 양쪽 맨 끝의 값을 빼고 곱하게 될 경우 노란색과 값이 같게 됨

   - 따라서 모든 값을 탐색하되 카펫이 가로 세로를 곱한 값이 넘어가는 경우 제외

vector<int> solution(int brown, int yellow) {
    int width = 3;
    while (true)
    {
        for (int height = 3; height <= width; height++)
            if (brown + yellow >= (width) * (height))
                if ((width - 2) * (height - 2) == yellow) return {width, height};
        width++;
    }
}

1.2 Second Algorithm

 - 위의 방법으로 했으나 제출할 때 오류가 생겨 생각해봄

   - 값이 같은데 카펫의 개수보다 작은 경우에 해당하는 값이 생김

     - 10, 10 인경우 (5,4)을 넘기고 (6,4)를 리턴함 (아시는분?????????)

       - 따라서 같은 값인 경우만 조건을 생성

vector<int> solution(int brown, int yellow) {
    int width = 3;
    while (true)
    {
        for (int height = 3; height <= width; height++)
            if (brown + yellow == (width) * (height))
                if ((width - 2) * (height - 2) == yellow) return {width, height};
        width++;
    }
}

2. 완성 코드

#include <vector>
using namespace std;

vector<int> solution(int brown, int yellow) {
    int width = 3;
    while (true)
    {
        for (int height = 3; height <= width; height++)
            if (brown + yellow == (width) * (height))
                if ((width - 2) * (height - 2) == yellow) return {width, height};
        width++;
    }
}

저작자표시 (새창열림)

'C++ Algorithm & Study > C++ & Algorithm Strategies' 카테고리의 다른 글

[Programmers] 멀리 뛰기  (0) 2023.01.24
[Programmers] 행렬의 곱셈  (0) 2023.01.23
[Programmers] 구명보트  (0) 2023.01.17
[Programmers] 이상한 문자 만들기  (0) 2023.01.16
[Programmers] 예상 대진표  (0) 2023.01.10
    'C++ Algorithm & Study/C++ & Algorithm Strategies' 카테고리의 다른 글
    • [Programmers] 멀리 뛰기
    • [Programmers] 행렬의 곱셈
    • [Programmers] 구명보트
    • [Programmers] 이상한 문자 만들기
    GameChoi
    GameChoi

    티스토리툴바