转载请注明出处!谢谢!

Kinds of Fuwas

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 <= MN <= 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

题意:找图中有多少个矩形!

思路:公式:n*(n-1)/2;逐层比较!

代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[251][251],b[5]={ 'B','J','H','Y','N'};
int main()
{int t,n,m;int i,j,k,l,s,ss;while(~scanf("%d",&t)){while(t--){scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%s",a[i]);ss=0;for(l = 0 ; l < 5 ; l++ ){for(i = 0 ;i < n ; i++ ){for( j = i + 1 ; j < n ; j++ ){s = 0 ;for( k = 0 ; k < m ; k++ ){if( a[i][k] == a[j][k] && a[i][k] == b[l]){s++;}}ss+= s*(s-1)/2;}}}printf("%d\n",ss);}}return 0;
}


zoj 2975 Kinds of Fuwas(数学题)相关推荐

  1. ZOJ 2975 Kinds of Fuwas(暴力)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2975 给出n*m的矩阵,要求算出四个角类型相同的小矩形的数目 使 ...

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

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

  3. ZOJ 3827 Information Entropy(数学题 牡丹江现场赛)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5381 Information Theory is one of t ...

  4. ZOJ 2975-K - Kinds of Fuwas-暴力+bitset

    给出一个n*m的矩阵 里面有BJHYN的 五种字母, 求出所有 矩形 满足 四个角的字母 是相同的 我们发现 如果对于任意两行,满足  这两行的 第   i,j,k位置的字母都一样,则 可以得到1*2 ...

  5. K - Kinds of Fuwas----(2015 summer training #4 (Qualifying))

    K - Kinds of Fuwas 时限:2000MS     内存:65536KB     64位IO格式:%lld & %llu 问题描述 In the year 2008, the 2 ...

  6. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  7. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  8. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  9. 杭电OJ题目分类(转载)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

最新文章

  1. Oracle中的iot_type,oracle IOT表学习
  2. NumPy基础用法总结
  3. 如何使用ui-router中的ui-sref将参数传递给控制器
  4. 使用subprocessm模块管理进程
  5. mysql查询时给字段加内容,mysql数据库查询之对应库对应表中的注释信息查询以及加字段查询...
  6. 【Python 】单引号和双引号有什么区别?
  7. 50种优化数据库的方法
  8. python3 rid1.7.4.2 控制台中文乱码_TL;DR - 有关 Python 2 和 Sublime Text 中文 Unicode 编码问题的分析与理解...
  9. archlinux php mysql,arch linux上安装 httpd+php+mysql+ openssl(转)
  10. 外媒:特斯拉2.5万美元新型电动车拟2023年推出 命名Model Q
  11. 自考那些事儿(四):软件开发工具(理论篇)
  12. 代码复审1234跟我一起来
  13. MAC微软远程桌面RDC不能全屏的的解决方法
  14. __init__在python中的用法_如何打“我爱你”的摩斯密码
  15. ubuntu系统下,Firefox火狐浏览器播放网页视频失败,显示未安装视频插件
  16. mysql rename数据库_为什么现在MySQL无法重命名数据库?
  17. OSPF网络可以没有BDR(实验)
  18. 如何理解国产操作系统,现状又是如何?
  19. Kafka之Controller(Broker的领导者)
  20. python opencv3 背景分割 mog2 knn

热门文章

  1. 多台Linux服务器时钟同步
  2. 电脑文件夹怎么设置密码?这2个方法一看就会!
  3. 王慧文:当下社会最稀缺的是“π型人才”
  4. 触龙说赵太后原文及翻译
  5. 给自家人做个招聘广告,前后端和移动工程师看过来
  6. 将print打印的内容保存到日志
  7. 全栈的好处:七天和两周
  8. pat 乙级 1094
  9. Lammps安装教程 windows版
  10. python音乐编程_基于python实现音乐播放器代码实例