E题求条
  • 板块灌水区
  • 楼主wanjiabao
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/12/14 22:36
  • 上次更新2024/12/15 09:55:57
查看原帖
E题求条
939957
wanjiabao楼主2024/12/14 22:36

掉大分了,上次才上青名,又要变绿帽子了。

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位置的不同,然后就这样了

2024/12/14 22:36
加载中...