Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
 User ID: Password:
Register

## 为什么会RE啊？求过路的帮忙看一看~

Posted by rongrongbiubiu at 2016-10-26 15:41:14 on Problem 1088
```// skingmy.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

class A{
public:
int x;
int y;
int high;
};//辅助表类

A a[1000] = { 0 };
int flag[1000][1000] = { -1 };
int dre[4] = { 0,0,1,-1 };//停停下上
int drec[4] = { 1,-1,0,0 };//右左停停
int array_l[1000][1000] = { 0 };
int length[1000] = { 0 };
int final = 0;

bool cmp(A first, A second)
{
return first.high<second.high;
}

int find_l(int R, int C, int k)
{
A temp;//a的邻居
sort(a, a + k, cmp);//将辅助表中的数据的值按照从小到大排序，但保证其在原矩阵中的行和列
for (int h = 0; h < k; h++)
{
int max = 0;
int f = 0;//设置标志记录当前位置是否为终点

for (int q = 0; q < 4; q++)
{
//从上下左右中去挑选比当前位置更低，且路径最长的点
temp.x = a[h].x + dre[q];
temp.y = a[h].y + drec[q];
temp.high = array_l[temp.x][temp.y];
if (temp.x >= 0 && temp.y >= 0 && temp.x < R && temp.y < C) {
if (a[h].high > temp.high)//该点不是终点
{
f = 1;//设置记号
if (max < flag[temp.x][temp.y])
max = flag[temp.x][temp.y];
}
}
}
if (f == 0)//当前位置就是终点时
{
flag[a[h].x][a[h].y] = 1;
length[h] = 1;
}
else
{
flag[a[h].x][a[h].y] = max + 1;
length[h] = max + 1;
}
if (final < length[h])
final = length[h];
}
return final;
}

int main()
{

int R, C, num;
int k = 0;
cin >> R;//输入行数
cin >> C;//输入列数
for (int i = 0; i<R; i++)
for (int j = 0; j<C; j++)
{
cin >> num;
a[k].x = i;
a[k].y = j;
a[k].high = num;
k++;//给辅助表赋值
array_l[i][j] = num;
}
int length_result=find_l(R,C,k);//寻找最长路径
cout << length_result;
getchar();
getchar();
return 0;
}

```

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator