炫酷1A啊。
思路就是 把所有的点大小排序。 然后从最小的开始。 访问。 对于每一个点 他的步数 step 等于 周围比他小的点的 最大步数 加一。
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
using namespace std;
#define ll long long
#define maxn 150+10
#define INF 1<<30
int d[5][3] = {{-1,0},{1,0},{0,-1},{0,1}};
struct po{
int x,y;
int v;
friend bool operator < (po a, po b){
return a.v < b.v;
}
};
int main (){
int counts;
scanf("%d",&counts);
while(counts--){
string s;
cin >> s;
int m,n;
int map1[maxn][maxn];
int step[maxn][maxn] = {0};
vector <po> p;
p.clear();
scanf("%d%d",&m,&n);
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
scanf("%d",&map1[i][j]);
po x;
x.v = map1[i][j];
x.x = i;
x.y = j;
p.push_back(x);
}
}
sort(p.begin(),p.end());
int ma = -1;
for(int i = 0; i < m * n; i++){
int flag = 0;
for(int j = 0; j < 4; j++){
int xx = p[i].x + d[j][0];
int yy = p[i].y + d[j][1];
if(xx >=0 && xx < m && yy >= 0 && yy < n){
if(map1[p[i].x][p[i].y] > map1[xx][yy]){
flag = 1;
step[p[i].x][p[i].y] = max(step[p[i].x][p[i].y], step[xx][yy] + 1);
}
}
}
if(!flag)
step[p[i].x][p[i].y] += 1;
ma = max(step[p[i].x][p[i].y], ma);
}
cout << s << ": ";
printf("%d\n",ma);
}
return 0;
}
想到了这一点就好做了。