[프로그래머스 C++] 두 원 사이의 정수 쌍
https://school.programmers.co.kr/learn/courses/30/lessons/181187
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
해결전략
수학
구현
정답코드
| #include <cmath> |
| using namespace std; |
| |
| long long solution(int r1, int r2) { |
| long long answer = 0; |
| |
| for(int i = 1; i <= r2; i++) |
| { |
| long long y1 = ceil(sqrt(pow(r1, 2) - pow(i, 2))); |
| long long y2 = floor(sqrt(pow(r2, 2) - pow(i, 2))); |
| |
| answer += (y2 - y1 + 1); |
| } |
| |
| answer *= 4; |
| |
| return answer; |
| } |
댓글을 사용할 수 없습니다.