ZOJ 2975 Kinds of Fuwas(暴力+排列组合)
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 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 hasN 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
Author: XUE, Zaiyue
Source: The 5th Zhejiang Provincial Collegiate Programming Contest
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char mp[][];
char fuwa[]={'B','J','H','Y','N'};
int t,n,m;
long long sum;
int main()
{
while(~scanf("%d",&t))
{
for(;t>;t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++) scanf("%s",mp[i]);
sum=;
for(int w=;w<;w++)
for(int i=;i<n-;i++)
for(int j=i+;j<n;j++)
{
long long l=;
for(int k=;k<m;k++)
{
if (mp[i][k]==mp[j][k] && mp[i][k]==fuwa[w])
l++;
}
sum=sum+l*(l-)/;//关键是排列组合,节省时间,C(l,2);
}
printf("%lld\n",sum);
}
}
return ;
}
ZOJ 2975 Kinds of Fuwas(暴力+排列组合)的更多相关文章
- 哈理工2015暑假集训 zoj 2975 Kinds of Fuwas
G - Kinds of Fuwas Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- ZOJ 2975 Kinds of Fuwas
K - Kinds of Fuwas Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu De ...
- ACM-ICPC 2017 Asia Xi'an J LOL 【暴力 && 排列组合】
任意门:https://nanti.jisuanke.com/t/20750 J - LOL 5 friends play LOL together . Every one should BAN on ...
- ZOJ 3725 Painting Storages(DP+排列组合)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output ...
- UVa Problem 10132 File Fragmentation (文件还原) 排列组合+暴力
题目说每个相同文件(01串)都被撕裂成两部分,要求拼凑成原来的样子,如果有多种可能输出一种. 我标题写着排列组合,其实不是什么高深的数学题,只要把最长的那几个和最短的那几个凑一起,然后去用其他几个验证 ...
- HDU 5816 状压DP&排列组合
---恢复内容开始--- Hearthstone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- BZOJ 1005 [HNOI2008]明明的烦恼 purfer序列,排列组合
1005: [HNOI2008]明明的烦恼 Description 自从明明学了树的结构,就对奇怪的树产生了兴趣......给出标号为1到N的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少 ...
- 洛谷P1246编码问题-排列组合,分类讨论
编码问题 题意就是a,b,c.....ab.....编码,给你一个字符串,输出这是第几个: 这里可以用暴力枚举,但也可以用组合数学的高超知识: 既然这样我就说一下排列组合的方法,如果要弄一个 各位数字 ...
- 10.1 csp-s模拟测试(b) X国的军队+排列组合+回文
T1 X国的军队 贪心,按$b-a$的大小降序排序,然后就贪心吧 #include<iostream> #include<cstdio> #include<algorit ...
随机推荐
- asp.net时间显示
DateTime dt = DateTime.Now;// Label1.Text = dt.ToString();//2005-11-5 13:21:25// Label2.Text = ...
- 【android】通过leakCanary找出程序内存泄露点
背景 内存泄露是咱新手比较头痛的问题,因为它不像崩溃,在开发环境可以根据提示的错误信息排查问题. 你都不知道咱的app是否哪个犄角旮旯藏着一个吞噬内存的黑洞. 排查android 内存泄露比较底层高端 ...
- Method Swizzling 剖析
一.背景介绍 关于Method Swizzling的文章一大堆,讲的非常好的也数不胜数.不过,很多人只是会用,知道一些注意点.深入一点问的话,估计就答得不好.归其原因就是对Method Swizzli ...
- 在MySQL中使用explain查询SQL的执行计划
1.什么是MySQL执行计划 要对执行计划有个比较好的理解,需要先对MySQL的基础结构及查询基本原理有简单的了解. MySQL本身的功能架构分为三个部分,分别是 应用层.逻辑层.物理层,不只是MyS ...
- 20145240《网络对抗》PC平台逆向破解_advanced
PC平台逆向破解_advanced shellcode注入 Shellcode实际是一段代码(也可以是填充数据),是用来发送到服务器利用特定漏洞的代码,一般可以获取权限.另外,Shellcode一般是 ...
- Could not reserve enough space for 1572864KB object heap
This problem might be caused by incorrect configuration of the daemon.For example, an unrecognized j ...
- Editor.md的安装使用(MarkDown)
1.官网下载:http://pandao.github.io/editor.md/ 2.使用例子: <!DOCTYPE html> <html lang="zh-cn&qu ...
- NAT模式下远程连接centos6虚拟机与虚拟机网络配置
最近装了centos,但是没有网络,也无法远程连接.关键是虚拟机中没有ip地址. 网上方法很多,但是每个人情况不一样,所以不尽适用. 1.解决这个问题,首先保证你的vmware的dhcp服务和net服 ...
- js 苹果手机 keyup 事件不生效的问题
$(document).on('keyup','input[name="txtInp"]',function(){}) 改 $(document).on('input proper ...
- html-常用块级及行级标签
1.常见块级标签 <h1></h1>......<h6></h6>:标题标签 h标签:标题标签,自动加粗,h1最大,h6最小 例:(前后隔一行) ...