Test instructions gives a rectangle asking how many sub-rectangles there are in the four corners of the letters are the same
At first, the violence wrote a first-in-one. Number and then enumerate the number of two columns and then hold the number down to determine whether there is no unexpected timeout.
And then I thought about it. When we have determined the number of two columns to look down when we find the tot edge and the first edge of the same letter these edges can be composed (tot-1) *tot a rectangle to satisfy the test instructions
In order to avoid repeated searches need a map to record the length of the rectangle because of the longest 100 we have retrieved the letter *1000*1000+ left column number *1000+ right column number
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include < String> #include <map>using namespace Std;int n,m;char a[300][300];int main () {int t; scanf ("%d", &t); while (t--) {map<int, int >q; Q.clear (); int sum=0; scanf ("%d%d", &n,&m); for (int i=1;i<=n;i++) scanf ("%s", a[i]+1); for (int i=1;i<=n-1;i++) {for (int. k=1;k<=m-1;k++) {for (int j=k+1;j<= m;j++) {if (a[i][k]!=a[i][j]) continue; int x=a[i][k]-' a '; if (q[x*1000000+k*1000+j]!=0) continue; int tot=1; for (int l=i+1;l<=n;l++) {if (A[l][j]==a[l][k]&&a[l][j]==a[i][j]) {tot++; Q[x*1000000+k*1000+j]=1; }} sum+= (tot-1) *TOT/2; }}} printf ("%d\n", sum); }}
ZOJ 2975 Thinking