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

2
2 2
BB
BB
5 6
BJHYNB
BHBYYH
BNBYNN
JNBYNN
BHBYYH

Sample Output

1
8
 #include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
using namespace std;
int main()
{
int a;
cin>>a;
while(a--)
{ int n,m,t;
cin>>n>>m;
char JU[][];//输入信息
for(int i=;i<n;i++)
for(int j=;j<m;j++)
cin>>JU[i][j];
char wa[]={"BJHYN"};
int he= ;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
for(int p=;p<;p++)
{
t=;
for(int l=;l<m;l++)
if(JU[i][l]==wa[p]&&JU[j][l]==wa[p])//划线……
t=t+;
he=he+t*(t-)/;//等差数列求和
}
}
printf("%d\n",he);
}
return ;
}
												

ZOJ 2975 Kinds of Fuwas的更多相关文章

  1. 哈理工2015暑假集训 zoj 2975 Kinds of Fuwas

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

  2. ZOJ 2975 Kinds of Fuwas(暴力+排列组合)

    Kinds of Fuwas Time Limit: 2 Seconds      Memory Limit: 65536 KB In the year 2008, the 29th Olympic ...

  3. ZOJ 2975 思维

    题意 给出一个矩形 问在其中存在多少子矩形 其四个角上的字母是一样的 一开始暴力写了一发 先枚举行数 再枚举两个列数 再向下枚举行数 判断能否 没有意外的超时了 后来想了想 当我们已经确定两个列数的时 ...

  4. The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974 题意:问四个角都有同一个福娃的矩形有多少个. #include<b ...

  5. nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest

    ZOJ Problem Set - 2965 Accurately Say "CocaCola"!  http://acm.zju.edu.cn/onlinejudge/showP ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. ZOJ2975 伪数组压缩+组合数

    Kinds of Fuwas Time Limit: 2 Seconds      Memory Limit:65536 KB In the year 2008, the 29th Olympic G ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. QDU_组队训练(ABEFGHKL)

    A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...

随机推荐

  1. 翻译:探索GLSL-用几何着色器(着色器库)实现法线可视化

    翻译:探索GLSL-用几何着色器(着色器库)实现法线可视化 翻译自: Exploring GLSL – Normal Visualizer with Geometry Shaders (Shader ...

  2. ngx_lua_API 指令详解(六)ngx.thread.spawn、ngx.thread.wait、ngx.thread.kill介绍

    摘要:通过lua-nginx-module中的ngx.thread同时执行多个任务. ngx_lua中访问多个第三方服务 ngx_lua中提供了ngx.socket API,可以方便的访问第三方网络服 ...

  3. ngx_lua_API 指令详解(二)ngx.re.match/find/gmatch/sub/gsub指令集合

    1.先来个官方的ngx.re.match location /ngx_re_match { default_type text/html; content_by_lua_block { local m ...

  4. Ubuntu 16.04开机自启Nginx简单脚本

    本文要记述的是最简单的Ubuntu下开机自启 nginx的脚本 这里将nginx装在了/usr/local/nginx目录下,nginx本身没有注册成服务,所以直接使用服务开机自启是不行的,除非自己写 ...

  5. html5 canvas创建阴影

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. es6笔记(2) let 和 const

    let命令 用来声明一个变量,和var非常类似 1.使用let声明的变量,所声明的变量只在命令所在的代码块中有效 { let a = 1; console.log(a); // 这里是可以使用的 } ...

  7. [转]LaTex常用数学符号整理

    转载自 http://blog.csdn.net/ying_xu/article/details/51240291 (自己保存方便查阅,侵删) 另一个网站 Markdown 添加 Latex 数学公式 ...

  8. __class__属性与元类

    class M(type): def __str__(self): return "gege" aa = "ccf" cc = "ccc" ...

  9. mac rsync文件传输

    rsync -avz filename servername:/filename --exclude '*.log' --exclude '*.pyc' --exclude '*.db' --excl ...

  10. 解决centos7下tomcat启动正常,无法访问项目的问题

    centos7防火墙不再采用iptables命令,改用firewalld 禁用防火墙命令: # systemctl stop firewalld.service # systemctl disable ...