ALineInTheSand @ 2021-11-14 20:25:26
#include<bits/stdc++.h>
using namespace std;
int m,mp[320][320],z,ans,T;
bool safe[320][320];
struct meteor{int t,x,y;};
meteor met[50020];
struct rec{int x,y;};
queue<rec> q;
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
void bfs(){
rec now;
now.x=0;now.y=0;
mp[0][0]=0;q.push(now);
while(q.size()){
now=q.front();q.pop();
T=mp[now.x][now.y];
while(T==met[z].t){
mp[met[z].x][met[z].y]=-2;
z++;
}
if(mp[now.x][now.y]==-1)continue;
for(int i=0;i<4;i++){
rec nxt;
nxt.x=now.x+dir[i][0];
nxt.y=now.y+dir[i][1];
if(nxt.x<0||nxt.y<0||nxt.x>300||nxt.y>300)
continue;
if(mp[nxt.x][nxt.y]==-1){
mp[nxt.x][nxt.y]=mp[now.x][now.y]+1;
if(safe[nxt.x][nxt.y]){
ans=mp[nxt.x][nxt.y];
return;
}
q.push(nxt);
}
}
}
return;
}
int main(){
cin>>m;
for(int i=0;i<=300;i++)
for(int j=0;j<=300;j++){
mp[i][j]=-1;
safe[i][j]=1;
}
for(int i=0;i<m;i++){
cin>>met[i].x>>met[i].y>>met[i].t;
safe[met[i].x][met[i].y]=0;safe[met[i].x-1][met[i].y]=0;
safe[met[i].x+1][met[i].y]=0;safe[met[i].x][met[i].y-1]=0;
safe[met[i].x][met[i].y+1]=0;
}
sort(met,met+m);
z=0;
ans=-1;
bfs();
cout<<ans;
return 0;
}
In file included from /usr/include/c++/8/bits/stl_algobase.h:71,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/predefined_ops.h: In instantiation of ‘constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = meteor*; _Iterator2 = meteor*]’:
/usr/include/c++/8/bits/stl_algo.h:1847:14: required from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:1885:25: required from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:1971:31: required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:4834:18: required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = meteor*]’
/tmp/compiler_406oeoc_/src:55:16: required from here
/usr/include/c++/8/bits/predefined_ops.h:43:23: 错误:no match for ‘operator<’ (operand types are ‘meteor’ and ‘meteor’)
{ return *__it1 < *__it2; }
~~~~~~~^~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/stl_iterator.h:892:5: 附注:candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)’
operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:892:5: 附注: template argument deduction/substitution failed:
In file included from /usr/include/c++/8/bits/stl_algobase.h:71,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/predefined_ops.h:43:23: 附注: ‘meteor’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
{ return *__it1 < *__it2; }
~~~~~~~^~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/stl_iterator.h:899:5: 附注:candidate: ‘template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)’
operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:899:5: 附注: template argument deduction/substitution failed:
In file included from /usr/include/c++/8/bits/stl_algobase.h:71,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/predefined_ops.h:43:23: 附注: ‘meteor’ is not derived from ‘const __gnu_cxx::__normal_iterator<_Iterator, _Container>’
{ return *__it1 < *__it2; }
~~~~~~~^~~~~~~~
/usr/include/c++/8/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = meteor*; _Value = meteor]’:
/usr/include/c++/8/bits/stl_heap.h:133:48: required from ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = meteor*; _Distance = long int; _Tp = meteor; _Compare = __gnu_cxx::__ops::_Iter_less_val]’
/usr/include/c++/8/bits/stl_heap.h:237:23: required from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = meteor*; _Distance = long int; _Tp = meteor; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_heap.h:342:22: required from ‘void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:1672:23: required from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:1933:25: required from ‘void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:1948:27: required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = meteor*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:1968:25: required from ‘void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = meteor*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]’
/usr/include/c++/8/bits/stl_algo.h:4834:18: required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = meteor*]’
/tmp/compiler_406oeoc_/src:55:16: required from here
/usr/include/c++/8/bits/predefined_ops.h:65:22: 错误:no match for ‘operator<’ (operand types are ‘meteor’ and ‘meteor’)
{ return *__it < __val; }
~~~~~~^~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/stl_iterator.h:892:5: 附注:candidate: ‘template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)’
operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:892:5: 附注: template argument deduction/substitution failed:
In file included from /usr/include/c++/8/bits/stl_algobase.h:71,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/predefined_ops.h:65:22: 附注: ‘meteor’ is not derived from ‘const __gnu_cxx::__normal_iterator<_IteratorL, _Container>’
{ return *__it < __val; }
~~~~~~^~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
from /usr/include/c++/8/bits/char_traits.h:39,
from /usr/include/c++/8/ios:40,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from /usr/include/c++/8/complex:45,
from /usr/include/c++/8/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/8/bits/stdc++.h:52,
from /tmp/compiler_406oeoc_/src:1:
/usr/include/c++/8/bits/stl_iterator.h:899:5: 附注:candidate: ‘template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)’
operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
^~~~~~~~
/usr/include/c++/8/bits/stl_iterator.h:899:5: 附注: template argument deduction/substitution failed:
In file included from /usr/include/c++/8/bits/stl_algobase.h:71,
from /usr/include/c++/8/bits/char_traits.h:39,
from
...
by Most_Goodlooking @ 2021-11-14 20:27:28
自己写一个cmp函数在sort那里
by ALineInTheSand @ 2021-11-14 20:30:08
@Most_Goodlooking 感谢大佬
by NetherDevil @ 2021-11-14 20:30:27
关键信息:
没有匹配的运算符重载。用 sort
给结构体排序的时候要给结构体重载小于号或者在第三个参数传一个 cmp
函数进去
by ud2_ @ 2021-11-14 20:32:35
遇到这种长编译错误,搜 required from here 就可以了。这句话意思是“导致错误的代码在这里”。