| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
STL排序就是强大。。。。贴个弱智代码#include <iostream>
#include <algorithm>
using namespace std;
#define NUM 120
struct node{
int x;
int y;
int num;
}N[NUM*NUM];
int M[NUM][NUM];
int P[NUM][NUM];
bool cmp(const node & a,const node &b){
return a.num>b.num;
}
int main()
{
int ans=1;
int h,w,temp;
cin>>h>>w;
int i,j,n;
for (i=0;i<h;i++) for (j=0;j<w;j++){
cin>>n;M[i][j]=n;
N[i*w+j].x=i;N[i*w+j].y=j;N[i*w+j].num=n;
}
sort(N,N+h*w,cmp);
for (i=0;i<h*w;i++){
temp=1;
if (N[i].y>0 && M[N[i].x][N[i].y-1]>N[i].num && P[N[i].x][N[i].y-1]+1>temp)
temp = P[N[i].x][N[i].y-1]+1;
if (N[i].y<w && M[N[i].x][N[i].y+1]>N[i].num && P[N[i].x][N[i].y+1]+1>temp)
temp = P[N[i].x][N[i].y+1]+1;
if (N[i].x>0 && M[N[i].x-1][N[i].y]>N[i].num && P[N[i].x-1][N[i].y]+1>temp)
temp = P[N[i].x-1][N[i].y]+1;
if (N[i].x<h && M[N[i].x+1][N[i].y]>N[i].num && P[N[i].x+1][N[i].y]+1>temp)
temp = P[N[i].x+1][N[i].y]+1;
P[N[i].x][N[i].y]=temp;
if (temp>ans) ans=temp;
}
cout<<ans<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator