반응형
문제 출처 :
https://www.codeground.org/practice/practiceProblemList
알고리즘 분석 :
문제 해결에 필요한 사항
1. 구현
알고리즘 문제보다는 삼성 문제들의 easy 문제는 구현 문제가 많은 것 같다.
이 문제 또한 각을 구해야하는 문제인데 수학적 지식이 없다면 또 풀수가 없는 문제인 것 같기도 하다.
getTheta에서 각을 구해준다. 이때 http://zzoyu.tistory.com/73 과정을 이용하여 아크 탄젠트를 이용하였다.
이렇게 양수에 해당하는 각을 구하고 난 뒤, +9를 한 이유는 해당하는 다트의 구간이 모두 18도이기 때문이다.
나머지는 조건문의 조건에 맞게 문제를 처리하면 해결할 수 있는 문제이다.
소스 코드 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <iostream> #include <cstdio> #include <cmath> using namespace std; double getTheta(long long x, long long y) { double degree = atan2(x, y) * 180 / 3.14159; if (degree < 0) return degree + 360; return degree; } int score[] = { 20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5 }; int main() { int tCase; scanf("%d", &tCase); for (int tc = 1; tc <= tCase; tc++) { int a, b, c, d, e; scanf("%d %d %d %d %d", &a, &b, &c, &d, &e); int n; scanf("%d", &n); int ans = 0; for (int i = 0; i < n; i++) { long long x, y; scanf("%lld %lld", &x, &y); double size = sqrt(x*x + y*y); long long angle = getTheta(x, y); angle = (angle + 9) % 360; if (size > e) ans += 0; else if (b <= size && size <= c) ans += score[angle / 18] * 3; else if (d <= size && size <= e) ans += score[angle / 18] * 2; else if (0 <= size && size <= a) ans += 50; else ans += score[angle / 18]; } cout << "Case #" << tc << '\n' << ans << endl; } return 0; } // This source code Copyright belongs to Crocus // If you want to see more? click here >> | Crocus |
반응형
'Applied > 알고리즘 문제풀이' 카테고리의 다른 글
[14568번] 2017 연세대학교 프로그래밍 경시대회 (0) | 2017.05.14 |
---|---|
[Codeground 12번] 방속의 거울 (0) | 2017.05.10 |
[Codeground 3번] 시험 공부 (0) | 2017.05.09 |
[Codeground 2번] 프로그래밍 경진대회 (0) | 2017.05.09 |
[3006번] 터보소트 (0) | 2017.05.06 |