| 比赛 | 
    防止浮躁的小练习v0.2 | 
    评测结果 | 
    AAAAAAAAAA | 
    | 题目名称 | 
    最长滑坡 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    KZNS | 
    运行时间 | 
    0.318 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    4.96 MiB  | 
    | 提交时间 | 
    2016-10-08 09:57:39 | 
显示代码纯文本
// KZ's
#include <fstream>
#include <algorithm>
#include <iostream>
using namespace std;
class poi {
public:
	int x,y,h;
	void push(int a,int b,int c) {
		x=a;
		y=b;
		h=c;
	}
	void pop(int &a,int &b,int &c) {
		a=x;
		b=y;
		c=h;
	}
}ls[250000];
bool cmppoi(poi a,poi b) {
	return a.h<b.h;
}
int main() {
	ifstream fin ("shunzhi.in");
	ofstream fout ("shunzhi.out");
	int mp[500][500]={0},r,c,u=0;
	fin>>r>>c;
	for (int i=0;i<r;i++)
		for (int j=0;j<c;j++) {
			fin>>mp[i][j];
			ls[u++].push(i,j,mp[i][j]);
		}
	sort(ls,ls+u,cmppoi);
	int x,y,h,ed[500][500]={0},mxed=0;	
	for (int i=0;i<u;i++) {
		ls[i].pop(x,y,h);
		int &edu=ed[x][y];
		if (x>0&&mp[x-1][y]<h&&ed[x-1][y]>edu)
			edu=ed[x-1][y];
		if (x+1<r&&mp[x+1][y]<h&&ed[x+1][y]>edu)
			edu=ed[x+1][y];
		if (y>0&&mp[x][y-1]<h&&ed[x][y-1]>edu)
			edu=ed[x][y-1];
		if (y+1<c&&mp[x][y+1]<h&&ed[x][y+1]>edu)
			edu=ed[x][y+1];
		edu+=1;
		mxed=mxed<edu?edu:mxed;
	}
	fout<<mxed<<endl;
	return 0;
}
// UBWH