본문 바로가기

USACO7

BOJ 14452 - Cow Dance Show (usaco silver, 이분탐색) https://www.acmicpc.net/problem/14452 이분탐색할때 mid값이 문제 조건에 맞는 지 판단하는 isPossible 함수를 짤 때, multiset이나 priority_queue를 이용하고 싶었으나 구현을 못해서 vector로 구현했더니 시간초과가 났던 문제.. Barking dog님의 코드를 참고했습니다. https://github.com/blisstoner/BOJ/blob/master/14452.cpp #include #include #include using namespace std; int n, t; int d[10000]; bool isPossible(int k) { multiset ms; int tot = k, time = 0; for (int i = 0; i < k;.. 2019. 10. 7.
BOJ 14170 - Counting Haybales (usaco silver, 차원압축, 세그먼트트리) https://www.acmicpc.net/problem/14170 분류를 차원압축과 세그먼트트리로 하긴 했지만 훨씬 쉽게 풀 수는 있다. 하지만, 차원압축에 익숙해지기 위한 예제로 사용하면 좋을 것 같다. #include #include #include #include using namespace std; const int MAX = 1 = 1; i--) arr[i] = arr[i * 2] + arr[i * 2 + 1]; } int sum(int s, int e, int node, int ns, int ne) { if (e > q; int x[100000], hsize=0; set xSet; unordered_map xHash; //입력 및.. 2019. 10. 3.
BOJ 11973 - Angry Cows (usaco silver, 이분탐색) https://www.acmicpc.net/problem/11973 딱 봐도 이분탐색. 구현하는걸 까먹어서 옛날 코드 참고해서 풀었다. 폭발반지름R 대신 폭발구간 R'에 대해 이분탐색하였다. #include #include using namespace std; int n,k,arr[50000]; /* 처음 짠 논리. 밑에서 간략화 했다. bool isPossible(int m) { int i = 0, cnt = 0;; while(cnt= n) break; } return i >= n ? true : false; } */ bool isPossible(int m) { int i = 0, cnt = 0; while(cnt n >> k; for (int i = 0; i > arr[i].. 2019. 10. 1.