| ||||||||||
| 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 | |||||||||
凭什么Time Limit!!!!!!!!!!!!!!!!!!!!!!!!!测试几组数据都对,速度也不慢啊#include <iostream.h>
class theN
{
public:
int h; //记录高度
int n; //记录长度
int Row; //记录位置
int Col;
theN(){h=1;n=1;Row=1;Col=1;}
};
main()
{
int Row,Col;
int max,i,j,k,tmp;
max=1;
cin>>Row>>Col;
const int N = Row*Col;
theN* h = new theN[N];
//获得数据
for(i=0;i<N;i++)
{
cin>>h[i].h;
}
//调试数据
for(k=0,i=0;i<Row;i++)
{
for(j=0;j<Col;j++)
{
h[k].Row=i;
h[k].Col=j;
k++;
}
}
//从大到小排序,交换:高度,位置
k = N;
for(i=1;i<N;i++)
{
for(j=1;j<k;j++)
{
if( h[j-1].h < h[j].h )
{
tmp = h[j-1].h;
h[j-1].h = h[j].h;
h[j].h = tmp;
tmp = h[j-1].Row;
h[j-1].Row = h[j].Row;
h[j].Row = tmp;
tmp = h[j-1].Col;
h[j-1].Col = h[j].Col;
h[j].Col = tmp;
}
}
k--;
}
/*
for(i=0;i<N;i++)
{
cout<<h[i].Row<<','<<h[i].Col<<':'<<h[i].h<<'\n';
}
cout<<'\n';
*/
for(i=0;i<N;i++)
{
for(j=i+1;j<N;j++)
{
//避免同值情况出现
if(h[i].h<=h[j].h)continue;
k = h[i].Row - h[j].Row;
tmp = h[i].Col - h[j].Col;
k*=k;tmp*=tmp;
if(tmp*k==0)
{
if(tmp==1||k==1)
{
if(h[i].n+1>h[j].n)
{
h[j].n = h[i].n+1;
if(h[i].n+1>max)max = h[i].n+1;
}
}
}
}
}
cout<<max<<'\n';
delete []h;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator