Hdu5024 online competition
You don't need to think about brute-force behavior. Just enumerate the two points extending to the four sides, which can be converted to a 90-degree bend at the maximum distance.
# Include
# Include
# Include
Using namespaceStd
; IntDir
[8
] [2
] = {0
,1
,0
,-1
,1
,0
,-1
,0
,1
,1
,1
,-1
,-1
,1
,-1
,-1
}; IntXia
[8
] [2
] = {1
,0
,-1
,0
,0
,-1
,0
,1
,1
,-1
,-1
,-1
,1
,1
,-1
,1
}; // The corresponding intN
; CharMap
[110
] [110
]; IntChange
(IntX
, IntY
, IntK
, IntS
) {IntMark
=0
; While (1
) {IntXx
,Yy
; If (X
<0
|X
> =N
|Y
<0
|Y
> =N
) Break; if (Map
[X
] [Y
] ='#'
) Break;Mark
++; If (S
=1
){Xx
=X
+Dir
[K
] [0
];Yy
=Y
+Dir
[K
] [1
];} Else {Xx
=X
+Xia
[K
] [0
];Yy
=Y
+Xia
[K
] [1
];}X
=Xx
;Y
=Yy
;} ReturnMark
;} Int main () {intI
,J
; While (~Scanf
("% D"
,&N
),N
) {(I
=0
;I
<N
;I
++)Scanf
("% S"
,Map
[I
]);
IntMax
=0
; (I
=0
;I
<N
;I
++) {(J
=0
;J
<N
;J
++ ){
If (Map
[I
] [J
] ='#'
) Continue; for (intK
=0
;K
<8
;K
++) {IntXx
=I
+Dir
[K
] [0
]; IntYy
=J
+Dir
[K
] [1
];
IntXxx
=I
+Xia
[K
] [0
]; IntYyy
=J
+Xia
[K
] [1
];
IntKk
=1
;Kk
+ =Change
(Xx
,Yy
,K
,1
);Kk
+ =Change
(Xxx
,Yyy
,K
,2
); If (Kk
>Max
)Max
=Kk
;}}}Printf
("% D \ n"
,Max
);} Return0
;}