알고리즘/구현 및 시뮬레이션
[B10657] - Cow Jog
tongnamuu
2018. 9. 23. 14:27
https://www.acmicpc.net/problem/10657
포지션별로 정리한 뒤 뒤에서부터 temp의 속도보다 크게되면 하나의 그룹으로 합쳐지므로
초기 답을 소의 마리수와 같게 둔 상태에서 합쳐질 때마다 답을 1씩 줄인다.
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<pair<int,int>>a(n); int ans = n; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); int temp = a[n - 1].second; for (int i = n - 1; i >= 0; i--) { if (a[i].second > temp) { ans--; } else temp=a[i].second; } cout << ans << '\n'; } | cs |