Algorithm/Programmers
programmers_멀쩡한 사각형_java
owoowo
2023. 5. 12. 11:13
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/62048
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public long solution(int w, int h) {
long answer = 0;
for(int i = 1; i< w; i++){
double y = equation(w, h, i);
answer += Math.floor(y); // y 좌표 내림 -> 해당 값의 개수 만큼 사각형 존재
}
answer *= 2; // 선의 위, 아래
return answer;
}
// 방정식
public double equation(int w, int h, int x){
double incline = -1 * ((double)h/(double)w);
double y = incline * x + h;
return y;
}
}