ZOJ 2975 Kinds of Fuwas

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   strong   

K - Kinds of Fuwas Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China as well as becoming a festival for people all over the world.

The official mascots of Beijing 2008 Olympic Games are Fuwa, which are named as Beibei, Jingjing, Haunhuan, Yingying and Nini. Fuwa embodies the natural characteristics of the four most popular animals in China -- Fish, Panda, Tibetan Antelope, Swallow -- and the Olympic Flame. To popularize the official mascots of Beijing 2008 Olympic Games, some volunteers make a PC game with Fuwa.

As shown in the picture, the game has a matrix of Fuwa. The player is to find out all the rectangles whose four corners have the same kind of Fuwa. You should make a program to help the player calculate how many such rectangles exist in the Fuwa matrix.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

The first line of each test case has two integers M and N (1 <= M, N <= 250), which means the number of rows and columns of the Fuwa matrix. And then there are M lines, each has N characters, denote the matrix. The characters -- ‘B‘ ‘J‘ ‘H‘ ‘Y‘ ‘N‘ -- each denotes one kind of Fuwa.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the number of the rectangles whose four corners have the same kind of Fuwa.

Sample Input

22 2BBBB5 6BJHYNBBHBYYHBNBYNNJNBYNNBHBYYH

Sample Output

18
 1 #include<iostream>   2 #include<string.h>   3 #include<stdio.h>   4 #include<ctype.h>   5 #include<algorithm>   6 #include<stack>   7 #include<queue>   8 #include<set>   9 #include<math.h>  10 #include<vector>  11 #include<map>  12 #include<deque>  13 #include<list>  14 using namespace std;    15 int main()  16 {  17     int a;  18     cin>>a;  19     while(a--)  20     {  21         22         int n,m,t;  23         cin>>n>>m;24         char JU[260][260];//輸入資訊  25         for(int i=0;i<n;i++)  26         for(int j=0;j<m;j++)  27         cin>>JU[i][j]; 28         char wa[]={"BJHYN"};29         int he=0    ;30         for(int i=0;i<n;i++)  31         for(int j=i+1;j<n;j++)  32         {  33             for(int p=0;p<5;p++)  34             {  35                 t=0;  36                 for(int l=0;l<m;l++)  37                 if(JU[i][l]==wa[p]&&JU[j][l]==wa[p])//劃線……  38                 t=t+1;  39                 he=he+t*(t-1)/2;//等差數列求和  40             }  41         }  42         printf("%d\n",he);  43     }  44     return 0;  45 }  
View Code

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.