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

求大大分析下为何显示WA?我觉得思路已经很明确了,测试数据也过了

Posted by wcx730916119 at 2013-05-31 17:26:08 on Problem 1088
思路是用结构体把每个点的i,j以及高度保存下来,
然后sort,
从高度最小项读起,找出其上下左右格子滑行距离最大的,然后+1作为该点的滑行距离(如果周围全是0,则该点为1,由于高度排序好了,所以只要是滑行距离非零的邻点一定可以到达)
最后输出滑行距离最大值
代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAX_SIZE=100+5;
struct Point
{
    int i,j,w;
};
bool cmp(Point a,Point b)
{
    return a.w<b.w;
}
int main()
{
    int m,n;
    //freopen("in.txt","r",stdin);
    scanf("%d %d",&m,&n);
    Point *point =new Point[m*n];
    int tr[MAX_SIZE][MAX_SIZE]={0};
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            scanf("%d",&point[n*i+j].w);
            point[n*i+j].i=i;
            point[n*i+j].j=j;
        }
    }
    sort(point,point+m*n,cmp);
    int Max=0;
    for(int i=0;i<m*n;i++)
    {
        int u=0;
        if(point[i].i!=0&&u<tr[point[i].i-1][point[i].j]) u=tr[point[i].i-1][point[i].j];//up
        if(point[i].i!=m-1&&u<tr[point[i].i+1][point[i].j]) u=tr[point[i].i+1][point[i].j];//down
        if(point[i].j!=0&&u<tr[point[i].i][point[i].j-1]) u=tr[point[i].i][point[i].j-1];//left
        if(point[i].j!=n-1&&u<tr[point[i].i][point[i].j+1]) u=tr[point[i].i][point[i].j+1];//right
        tr[point[i].i][point[i].j]=u+1;
        printf("h[%d][%d]=%d\n",point[i].i,point[i].j,u+1);
        if(Max<u+1) Max=u+1;
    }
    printf("%d\n",Max);
    return 0;
}

Followed by:

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

Content:

Home Page   Go Back  To top


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