从小到大排:
struct node{
int id,dep;ll t,ans;
bool operator <(const node &a) const{
return t>a.t;
}
}p[maxn];
/*
bool operator <(node a,node b){
return a.t>b.t;
}
*/
从大到小排:
struct node{
int id,dep;ll t,ans;
bool operator <(const node &a) const{
return t<a.t;
}
}p[maxn];
/*
bool operator <(node a,node b){
return a.t<b.t;
}
*/
以cf1063B为例
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a) memset(a,0,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=2000+5;
struct node{
int x,y,l,r;
bool operator <(const node &a) const{
if(l==a.l) return r<a.r;
return l<a.l;
}
};
int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};
int vis[maxn][maxn];
char a[maxn][maxn];
int n,m,X,Y,L,R,cnt;
bool check(int x,int y){
return x>=1 && x<=n && y>=1 && y<=m && !vis[x][y] && a[x][y]!='*';
}
void bfs(){
priority_queue<node> q;
q.push(node{X,Y,L,R});
cnt+=1;vis[X][Y]=1;
while(!q.empty()){
node t=q.top();q.pop();
for(int i=0;i<4;i++){
int tx=t.x+dx[i];
int ty=t.y+dy[i];
if(!check(tx,ty)){
continue;
}
if(i==0 || i==3){
cnt++;
vis[tx][ty]=true;
q.push(node{tx,ty,t.l,t.r});
}
else if(i==1){
if(t.r>=1){
cnt++;
vis[tx][ty]=true;
q.push(node{tx,ty,t.l,t.r-1});
}
}
else if(i==2){
if(t.l>=1){
cnt++;
vis[tx][ty]=true;
q.push(node{tx,ty,t.l-1,t.r});
}
}
}
}
}
int main(){
cin>>n>>m;
cin>>X>>Y;
cin>>L>>R;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
bfs();
cout<<cnt<<endl;
}
注意,重载运算operator只和priority_queue搭配的时候,与一般排序定义相反。
否则和普通排序一样