글
[KOI]전국본선 2013 중등부 첫번째 문제
KOI (정보올림피아드) 기출 풀이
2019. 1. 26. 14:53
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 | #include <stdio.h> #include <algorithm> #include <vector> using namespace std; struct ANIMAL { int y, x; }; vector< int > hunter; vector<animal> animal; bool comp( const ANIMAL& a, const ANIMAL& b) { return (a.x < b.x); } bool is_kill( const ANIMAL& a, const int h, const int len) { int dist = abs (a.x - h) + a.y; if (dist <= len) return true ; else return false ; } int main() { int M, N, L; scanf ( "%d %d %d" , &M, &N, &L); hunter.resize(M); animal.resize(N); for ( int i = 0; i < M; ++i) { scanf ( "%d" , &hunter[i]); } for ( int i = 0; i < N; ++i) { scanf ( "%d %d" , &animal[i].x, &animal[i].y); } sort(hunter.begin(), hunter.end()); sort(animal.begin(), animal.end(), comp); int ret = 0; for (auto ani : animal) { auto target = lower_bound(hunter.begin(), hunter.end(), ani.x) - hunter.begin(); if (is_kill(ani, hunter[target], L)) { ++ret; } else { if (target > 0) { --target; if (is_kill(ani, hunter[target], L)) { ++ret; } } } } printf ( "%d\n" , ret); return 0; } |