1. 程式人生 > 實用技巧 >vuex中modules的基礎用法

vuex中modules的基礎用法

暑假大集訓模擬賽12 T2

演算法分析

  • 看起來很像個一眼題 直接列舉周圍四個點 然後求最小差值就好了
  • 但是我們多手玩幾組樣例就會發現這個是不對的 因為有可能會出現一個大坑裡面套了一個小坑的情況 類似 10 5 2 5 10這樣
  • 而看資料範圍300 那就搜唄
  • 當前這個點肯定是要向四周幾個點搜 而真正限制這個點水面高度的其實是最矮的一個方塊 (木桶效應)
  • 因此我們可以用一個堆來維護低的點 因為它一定是點的短板 然後進行bfs 去找出每一個符合條件 可以更新的塊

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn = 305;
int h[maxn][maxn];
int w[maxn][maxn];
int vis[maxn][maxn];
int n,m;
//w為水平面高度 h為實際高度
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

struct node{
	int x,y,v;//位置與實際高度
	node(){};
	node(int a,int b,int c){
		x = a,y = b,v = c;
	}
	bool operator < (const node &A)const{
		return v > A.v;
	}
};

priority_queue<node> q;
queue<node> Q;

void bfs(node s){
	Q.push(s);
	while(!Q.empty()){
		node u = Q.front();Q.pop();
		if(w[u.x][u.y] != -1)continue;
		w[u.x][u.y] = s.v;
		for(int k = 0;k < 4;++k){
			int tx = u.x + dx[k];
			int ty = u.y + dy[k];
			if(tx < 1 || tx > n || ty < 1 || ty > m)continue;
			if(w[tx][ty] != -1)continue;
			if(h[tx][ty] <= s.v)Q.push(node(tx,ty,0));
			else if(!vis[tx][ty])q.push(node(tx,ty,h[tx][ty])),vis[tx][ty] = 1;
		}
	}
}


int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i){
		for(int j =1;j <= m;++j){
			scanf("%d",&h[i][j]);
			w[i][j] = -1;
			if(i == 1 || j == 1 || i == n || j == m)q.push(node(i,j,h[i][j] < 0 ? 0 : h[i][j])),vis[i][j] = 1;//如果到邊界就入隊 從i邊界開始搜起
		}
	}
	while(!q.empty()){
		node now = q.top();
		q.pop();
		if(w[now.x][now.y] != -1)continue;//減枝
		bfs(now);
	}
	for(int i = 1;i <= n;++i){
		for(int j = 1;j <= m;++j)
			printf("%d ",w[i][j] - h[i][j]);
		printf("\n");
	}
	return 0;
}