掉大分了,上次才上青名,又要变绿帽子了。
WA2个点代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int h,w,p,q,x,s[505][505],dx[4]={1,0,0,-1},dy[4]={0,-1,1,0};
bool vis[505][505];
struct node{
int x,y;
bool operator<(const node &o)const{
return s[x][y]>s[o.x][o.y];
}
};
set<node>st;
signed main(){
cin>>h>>w>>x>>p>>q;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++)cin>>s[i][j];
}
vis[p][q]=1;
for(int i=0;i<4;i++){
if(p+dx[i]>=1&&p+dx[i]<=h&&q+dy[i]>=1&&q+dy[i]<=w)st.insert({p+dx[i],q+dy[i]}),vis[p+dx[i]][q+dy[i]]=1;
}
s[501][501]=(s[p][q]-1)/x;
while(!st.empty()){
auto a=(st.lower_bound({501,501}));
if(a==st.end())break;
node n=*a;
int tx=n.x,ty=n.y;
st.erase({tx,ty});
s[p][q]+=s[tx][ty];
s[501][501]=(s[p][q]-1)/x;
for(int i=0;i<4;i++){
if(tx+dx[i]>=1&&tx+dx[i]<=h&&ty+dy[i]>=1&&ty+dy[i]<=w&&vis[tx+dx[i]][ty+dy[i]]==0)st.insert({tx+dx[i],ty+dy[i]}),vis[tx+dx[i]][ty+dy[i]]=1;
}
}
cout<<s[p][q];
}
WA7个点代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int h,w,p,q,x,s[505][505],dx[4]={1,0,0,-1},dy[4]={0,-1,1,0};
bool vis[505][505];
struct node{
int x,y;
bool operator<(const node &o)const{
return s[x][y]>s[o.x][o.y];
}
};
set<node>st;
signed main(){
cin>>h>>w>>x>>p>>q;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++)cin>>s[i][j];
}
vis[p][q]=1;
for(int i=0;i<4;i++){
if(p+dx[i]>=1&&p+dx[i]<=h&&q+dy[i]>=1&&q+dy[i]<=w)st.insert({p+dx[i],q+dy[i]}),vis[p+dx[i]][q+dy[i]]=1;
}
s[501][501]=(s[p][q]-1)/x;
while(!st.empty()){
auto a=(st.lower_bound({501,501}));
if(a==st.end())break;
node n=*a;
int tx=n.x,ty=n.y;
s[p][q]+=s[tx][ty];
s[501][501]=(s[p][q]-1)/x;
for(int i=0;i<4;i++){
if(tx+dx[i]>=1&&tx+dx[i]<=h&&ty+dy[i]>=1&&ty+dy[i]<=w&&vis[tx+dx[i]][ty+dy[i]]==0)st.insert({tx+dx[i],ty+dy[i]}),vis[tx+dx[i]][ty+dy[i]]=1;
}
st.erase({tx,ty});
}
cout<<s[p][q];
}
显而易见的,它俩只是st.erase位置的不同,然后就这样了