■
動かない理由は後で考える。
class MinDifference { public: int closestElements(int A0, int X, int Y, int M, int n) { int res=10000; vector<int> a(1,A0); for(;a.size()<n;a.push_back(((a.back()*X)+Y)%M)); sort(a.begin(), a.end()); vector<int> buf; adjacent_difference(a.begin(), a.end(), buf); return buf[min_element(buf.begin() + 1, buf.end())];; } };
エラーメッセージは下記。
MinDifference.cpp: In member function `int MinDifference::closestElements(int, i nt, int, int, int)': MinDifference.cpp:113: error: no match for 'operator[]' in 'buf[std::min_element [with _ForwardIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int, st d::allocator<int> > >]((&buf)->std::vector<_Tp, _Alloc>::begin [with _Tp = int, _Alloc = std::allocator<int>](), (&buf)->std::vector<_Tp, _Alloc>::end [with _Tp = int, _Alloc = std::allocator<int>]())]' /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:462: note: candi dates are: typename _Alloc::reference std::vector<_Tp, _Alloc>::operator[](size_ t) [with _Tp = int, _Alloc = std::allocator<int>] /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:476: note: type name _Alloc::const_reference std::vector<_Tp, _Alloc>::operator[](size_t) const [with _Tp = int, _Alloc = std::allocator<int>] /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_numeric.h: In function `_ OutputIterator std::adjacent_difference(_InputIterator, _InputIterator, _OutputI terator) [with _InputIterator = __gnu_cxx::__normal_iterator<int*, std::vector<i nt, std::allocator<int> > >, _OutputIterator = std::vector<int, std::allocator<i nt> >]': MinDifference.cpp:112: instantiated from here /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_numeric.h:279: error: no match for 'operator*' in '*__result' MinDifference.cpp:112: instantiated from here /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_numeric.h:283: error: no match for 'operator++' in '++__result' /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_numeric.h:286: error: no match for 'operator++' in '++__result'