02-23 20:03
벤치마킹
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 가족소고기외식
- 에어아시아
- 중학교입학수학문제
- 영통외식
- 커피쏟음
- 사진문자추출
- 아이혼자다녀옴
- 양양솔비치 뷔페
- 사진문자추출하기
- 결항전문
- 커피
- 양양솔비치아침
- 홍시스무디
- 양양솔비치조식
- 편도수술
- 오트눈썰매장
- 영통역소고기
- 영통칠프로칠백식당
- 주차넉넉
- DFS
- 검색완료
- 파이썬
- 사진에서 글자추출
- 푸르지오포레피스
- 결항
- 종이캐리어
- 싱가폴중학교수학문제
- 양양솔비치세프스키친
- 당근마켓중고차
- 고마워다음
Archives
- Today
- Total
너와나의 관심사
leetcode 1610 문제 풀이 본문
https://leetcode.com/problems/maximum-number-of-visible-points/
Maximum Number of Visible Points - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
아이디어: view point 에서 angle 각도를 구해서 정렬 한뒤에 sort -> 그위에 upper_bound 를 통해서 index 갯수를 전체 탐색
nlog(n)
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 | #define PI 3.1415926535 using namespace std; double arr[200001]; class Solution { public: int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) { int felxAnswer = 0; int cnt = 0; for (auto &pos : points) { if (pos == location) { felxAnswer++; continue; } double tmp = getDegree(pos[0] - location[0], pos[1] - location[1]); arr[cnt++] = tmp; arr[cnt++] = tmp + 360.0f; } sort(arr, arr + cnt); int range = 0; int ret_max = 0; for (int i = 0; i < cnt; i++) { range = upper_bound(arr + i, arr + cnt, arr[i] + angle) - (arr + i); ret_max = range > ret_max ? range : ret_max; } return ret_max + felxAnswer; } double getDegree(int x, int y) { double ret = atan2(y, x) * 180 / PI; return ret; } }; | cs |
Comments