옵션 |
|
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 | #include <vector> #include <algorithm> #include <functional> #include <iostream> #include <map> using namespace std; class FilipTheFrog{ public: int countReachableIslands(vector<int> positions, int L){ map<int, int> reachable; reachable[0] = positions[0]; for (map<int, int>::iterator map_iter = reachable.begin(); map_iter != reachable.end(); map_iter++) { for (unsigned int i = 0; i < positions.size(); i++) { if (abs(map_iter->second - positions[i]) <= L) { if (reachable.find(positions[i]) == reachable.end()) { reachable[reachable.size()] = positions[i]; } } } } return reachable.size(); } }; int main(){ FilipTheFrog result_class; int result = result_class.countReachableIslands({ 4, 7, 1, 3, 5 }, 1); cout << result << endl; return 0; } | cs |