本帖最后由 人造人 于 2016-8-8 01:05 编辑 #include<stdio.h>
#include<stdlib.h>
struct hill
{
int height;
int pass;
}*path;
int R, L;
int slide(int x, int y)
{
int i, temp, longest = 0;
int d[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
for(i = 0; i < 4; i++)
{
if(x + d[i][0] < 0 || x + d[i][0] == R || y + d[i][1] < 0 || y + d[i][1] == L)
continue;
if((path + (x + d[i][0])*L + y + d[i][1])->height >= (path + x*L + y)->height)
continue;
if((path + (x + d[i][0])*L + y + d[i][1])->pass)
temp = (path + (x + d[i][0])*L + y + d[i][1])->pass;
else
temp = slide(x + d[i][0], y + d[i][1]);
longest = temp > longest ? temp : longest;
}
(path + x * L + y)->pass = 1 + longest;
return 1 + longest;
}
int main()
{
int i, j, length, longest = 0;
/*
scanf("%d", &R);
scanf("%d", &L);*/
struct test
{
int i;
int j;
};
i = sizeof(struct test);
i = sizeof(2 * 3 * sizeof(struct hill));
path = malloc(sizeof(R * L * sizeof(struct hill)));
for(i = 0; i < R; i++)
{
for(j = 0; j < L; j++)
{
scanf("%d", &((path + i * L + j)->height));
(path + i * L + j)->pass = 0;
}
}
/*
for(i = 0; i < R; i++)
{
for(j = 0; j < L; j++)
{
if((path + L * i + j)->pass)
length = (path + L*i + j)->pass;
else
length = slide(i, j);
if(length > longest)
longest = length;
}
}*/
free(path);
printf("%d", longest);
return 0;
}
只是找了一个问题,其它还没看
51 行 path = malloc(sizeof(R * L * sizeof(struct hill)));
你认为 sizeof(2 * 3 * sizeof(struct hill)) 应该是多少 |