์ด์งํ์
-
[BaekJoon] 10816๋ฒ : ์ซ์์นด๋ 2SW Test/BaekJoon 2021. 4. 21. 03:53
์ด ๊ธ์ c++๋ก ํ์ด๋ฅผ ์์ฑํ์์ต๋๋ค. ๋ฌธ์ ์์ ํ์ด ์ด๋ถํ์์์ ์ฐพ์์ผ ํ target ์์์ ์ธ๋ฑ์ค ์ค ๊ฐ์ฅ ์์ ๊ฐ๊ณผ ๊ฐ์ฅ ํฐ ๊ฐ์ ์ฐพ์ ๋นผ๋ ๊ฐ์ด ๊ฐ์์ ๋๋ค. ์ง์ ๊ตฌํํ ์ ์์ง๋ง, ํท๊ฐ๋ฆด ์ํ์ด ์๊ธฐ ๋๋ฌธ์ STL ์ค upper_bound์ lower_bound ๊ฐ์ ์ธ ์ ์์ต๋๋ค. #include #include using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); long long arr[100000]; int num; cin>>num; for(int i=0;i>arr[i]; } sort(arr, arr+num); int n; cin>>n; for(int i=0;i>ans; bool check = false; lo..
-
[BaekJoon] 1920๋ฒ : ์ ์ฐพ๊ธฐSW Test/BaekJoon 2021. 4. 21. 03:43
์ด ๊ธ์ c++๋ก ํ์ด๋ฅผ ์์ฑํ์์ต๋๋ค. ๋ฌธ์ ์์ ํ์ด ์ด ๋ฌธ์ ๋ ๊ฐ๋จํ๊ฒ map, set STL์ ์ฌ์ฉํด์ ํ๋ฉด ์๊ฐ์ด๊ณผ๊ฐ ๋ฉ๋๋ค. ์ด์งํ์ ํธ๋ฆฌ๋ก ์ฝ์ , ์ ๋ ฌ ๊ณผ์ ์์ ์๊ฐ์ด ๋ ๊ฑธ๋ ค์ ์ด์งํ์๊ณผ ์๊ฐ๋ณต์ก๋๋ O(logN)์ผ๋ก ๊ฐ์ง๋ง ๋๋ฆฝ๋๋ค. ์ด์งํ์ ์ฝ๋๋ฅผ ์๋์ ๊ฐ์ด ์ง์ ๊ตฌํํด๋ ๋์ง๋ง, STL์ binary_search ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ณด๋ค ํธ๋ฆฌํฉ๋๋ค. c, c++ stream ๋๊ธฐํ ๋๋ ์ฝ๋์ ๋ฒํผ ๋น์์ฃผ๋ ์ฝ๋๋ ์์ด์ผ ์๊ฐ์ด๊ณผ๊ฐ ๋ํ๋์ง ์์ต๋๋ค. #include #include using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int arr[100005]; int num; cin>>num; for(int i..