← Back to topics
Topic

Triangles

m
msantl
Can i get a little help about this task?

I tried but i doesn't work.
http://www.z-trening.com/new/www/html/submit.php?subm_stat=1&submit=7100043169

My idea is to find maximal height of a "white" triangle looking form above, under, left and right.
n
nikola
Just look at the picture carefully, and you'll see what is your mistake... Look little triangles, and where is the top of each little triangle... One points up and the second one points down and so on.. I hope this will help you, if not I will give you more precisely hint.
m
msantl
I think i know what you mean. thanks
m
msantl
i still get 2 WA

http://www.z-trening.com/new/www/html/submit.php?subm_stat=1&submit=7100043911

Is it necessary to check left and right, or is top and down enough ?
n
nikola
I didn't understand exactly what are you doing, but I think your mistake is in row number 76 and 98.

Example:
Row 76: dp[x][y]=min(min(dp[x-1][y-1],dp[x-1][y+1]),dp[x-1][y])+1;
You should check
if (a[x-1, y] = "_") then dp[x, y] = min(dp[x-1][y-1], dp[x-1, y+1])
else dp[x, y] = 1

As you see, the top of the first triangle is down, the next one's is up, then down, up, ... That is another hint for you... and also you should check each second little triangle...
n
nikola
I hope this will help you...
m
msantl
tnx for your help, my bug was in test
1 -
and
1 #
, and in check

if(a[x][y]==' ' || a[x][y]=='#') continue; ,

sometimes when
a[x][y]
was ' ' it didn't recgonized it.