Make Unreal REAL.
article thumbnail
Level 2. 멀쩡한 사각형

 

 

대각선을 일차 함수로 생각해 int 형변환으로 소숫점을 날리면서 더하면 된다.

 

#include <iostream>

#define f(x) int(a * (x) + b)

using namespace std;

long long solution(int w, int h)
{
    long long answer = 0;
    double b = h, a = -(b / w);

    for (int x = 1; x <= w; ++x)
        answer += f(x);

    return answer + answer;
}

'자료구조 & 알고리즘 > 프로그래머스' 카테고리의 다른 글

Level 2. 하노이의 탑  (0) 2023.06.12
Level 2. 모음사전  (0) 2023.06.11
Level 2. 행렬 테두리 회전하기  (0) 2023.06.09
Level 0. 수열과 구간 쿼리 4  (1) 2023.06.08
Level 2. 소수 찾기  (0) 2023.06.07
profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그