zoj 2975 Kinds of Fuwas

来源:互联网 发布:unity3d 沙盒fps源码 编辑:程序博客网 时间:2024/05/21 14:40
Kinds of Fuwas

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 integerT (1 <= T <= 50) which is the number of test cases. And it will be followed byT 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 areM 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
题目分析:全部遍历,每次两列进行判断,每次算出字母在所求的列出现的次数!然后组合下! #include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;#include<map>int main(){int n;char fuwa[6]="BJHYN";scanf("%d",&n);getchar();while(n--){int i,j,a,b,k;char s[1001][1001];int num[1000];scanf("%d%d",&a,&b);int ans=0;for(i=0;i<a;i++)scanf("%s",s[i]);map<char,int>mymap;//调用map容器     mymap.clear() ;    mymap[fuwa[0]]=0;    mymap[fuwa[1]]=1;    mymap[fuwa[2]]=2;    mymap[fuwa[3]]=3;    mymap[fuwa[4]]=4;for(i=0;i<b-1;i++)//逐列进行 ,第i列  { for(j=i+1;j<b;j++)//逐列进行 ,第j列   {  memset(num,0,sizeof(num));  for(k=0;k<a;k++)  {  if(s[k][i]==s[k][j])//两列进行比较   {  num[mymap[s[k][i]]]++;//两列相同的次数 }}for(k=0;k<5;k++)//组合数! {ans=ans+num[k]*(num[k]-1)/2; }  } } printf("%d\n",ans);}return 0;} 

0 0