http://acm.fzu.edu.cn/problem.php?pid=2225 problem Description
After defeating Iki Probrand, Nome Probrand, Xiao Ming students began to challenge Hade Probrand.
After a battle, he launched a big wave of attacks. In order to resist the attack, the students put magic array on the side of the magic array, and then he did not know that he put a number of magic array. It takes time to reclaim the magic array, in order to withstand the next wave of attack, the small tea students need to know that they have a number of magical array, because of the urgency of the situation, the task needs to be done by you.
The Magic matrix is triangular, such as
.............
. x.. X....x ...
..... xxx. x.x.
..... xxxxx.
.............
These are all thought to be magic matrices.
(that is, the triangles are three vertices (i,j), (I+k,j-k), (I+k,j+k), and the edges are ' x '. The elements in the middle of the triangle are not required. An ' x ' can belong to more than one magical array at a time. A single ' x ' also counts as a magical array. )
The site can be thought of as a nxm rectangle, each positioned as '. ' means nothing, or ' x ' indicates a magical array.
Input
The first line is an integer t (t<=10), which represents the total T-group test data.
The first row of each set of data contains two integers, N M (n,m≤1000), representing the size of the matrix.
Next n lines, m letters per line are '. ' or ' x '.
Output
Each set of data outputs has a single row, the output format is "case #x: Y", X starts at 1, represents the data group number, and Y represents the number of corresponding magic arrays.
Sample Input1 3 3. x. xxx ...Sample OutputCase #1:5SourceFOJ Award-April 2016 (school match)
#include <cstdio>#include<queue>#include<stack>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#defineLson 2*root#defineRson 2*root+1#defineMet (A, B) (Memset (A,b,sizeof (a)))typedefLong LongLL;ConstLL mod =1000000007;ConstLL inf= 1e9+7;Const intN =1100;CharS[n][n];intDp[n][n], dl[n][n], dr[n][n];///right, bottom left, right bottom record continuous, and finally judge can increase the large triangle, the code is very easy to readintMain () {intT, icase=1; scanf ("%d", &T); while(t--) { intI, J, K, N, M, cnt=0; scanf ("%d%d", &n, &m); Met (S,0); Met (DP,0); Met (DL,0); Met (DR,0); for(i=1; i<=n; i++) {scanf ("%s", s[i]+1); for(j=1; j<=m; J + +) { if(s[i][j]=='x') {CNT++; DP[I][J]= Dl[i][j] = Dr[i][j] =1; } } } for(I=n; i>=1; i--) for(J=m; j>=1; j--) { if(Dp[i][j]) dp[i][j]+ = dp[i][j+1]; if(Dl[i][j]) dl[i][j]+ = dl[i+1][j-1]; if(Dr[i][j]) dr[i][j]+ = dr[i+1][j+1]; } for(i=1; i<=n; i++) for(j=1; j<=m; J + +) { for(k=1; K<=min (Dl[i][j], dr[i][j]); k++) { if(dp[i+k][j-k]>=2*k+1) CNT++; }} printf ("Case #%d:%d\n", icase++, CNT); } return 0;}
(Sort of DP bar) The magic of the small tea (Fzu 2225)