G - 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 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

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

Sample Output

1
8 当时训练赛的时候做的也比較麻烦,并没有非常成熟的思维去迅速组织搞笑代码。这是改进后的代码。
 
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int INF=260;
char cnt[INF][INF];
int n,m; void before()
{
cin>>n>>m;
for(int i=0; i<n; i++)
scanf("%s",cnt[i]);
} int main()
{
int t;
cin>>t;
while(t--)
{
before();
int sum=0;
for(int i=0; i<m-1; i++)//前两个for循环 控制列变换
{
for(int j=i+1; j<m; j++)
{
map< char ,int >dict; // 统计每一个字母个数
set<char>xx; // 统计字母种类
for(int k=0; k<n; k++) //控制行数
{
if(cnt[k][i]==cnt[k][j])
{
dict[cnt[k][j]]++;
xx.insert(cnt[k][j]);
}
}
set<char >::iterator it;
for(it=xx.begin(); it!=xx.end(); it++)
{
//如果某两列 出现n对同样的 则矩形数目为 n*(n-1)/2个
sum+=dict[*it]*(dict[*it]-1)/2;
}
}
}
cout<<sum<<endl;
}
return 0;
}

哈理工2015暑假集训 zoj 2975 Kinds of Fuwas的更多相关文章

  1. ZOJ 2975 Kinds of Fuwas

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

  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. 哈理工2015 暑假训练赛 zoj 2976 Light Bulbs

    MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatusid=14946">Practice ...

  4. 哈理工2015暑假训练赛 zoj 2078Phone Cell

    Phone CellTime Limit:10000MS    Memory Limit:32768KB    64bit IO Format:%lld & %llu SubmitStatus ...

  5. ZZUACM 2015 暑假集训 round 01

    A. Encoding Problem Description Given a string containing only 'A' - 'Z', we could encode it using t ...

  6. 2015UESTC 暑假集训总结

    day1: 考微观经济学去了…… day2: 一开始就看了看一道题目最短的B题,拍了半小时交了上去wa了 感觉自己一定是自己想错了,于是去拍大家都过的A题,十分钟拍完交上去就A了 然后B题写了一发暴力 ...

  7. STL 入门 (17 暑假集训第一周)

    快速全排列的函数 头文件<algorithm> next_permutation(a,a+n) ---------------------------------------------- ...

  8. 暑假集训Day2 互不侵犯(状压dp)

    这又是个状压dp (大型自闭现场) 题目大意: 在N*N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. ...

  9. 暑假集训Day1 整数划分

    题目大意: 如何把一个正整数N(N长度<20)划分为M(M>=1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式. 输入格式: 第一行一个正整数T(T<= ...

随机推荐

  1. 【1】Jdk1.8中的HashMap实现原理

    HashMap概述 HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操作,并允许使用null值和null键.此类不保证映射的顺序,特别是它不保证该顺序恒久不变. 内部实现 ...

  2. React Native应用实现步骤

    React Native应用实现步骤 在整个应用设计中,始终按照自下而上的原则进行.在大型的项目中,自下而上的设计方式简单,可以并行工作,并且可以在构建的同时写测试用例. React Native设计 ...

  3. [Android]异常1-duplicate files during packaging of

    异常原因: 可能一>项目存在重复资源文件 可能二>Android Studio与源代码Android Studio不一致 解决方法有: 解决一>查找重复资源,删除或者修改文件 解决二 ...

  4. 遍历select搜索结果,只取数字标key值,防止重复

    //遍历select搜索结果,只取数字标key值,防止重复 foreach ($row as $key => $value) { if (is_int($key)) { echo $value; ...

  5. 【sqli-labs】 less53 GET -Blind based -Order By Clause -String -Stacked injection(GET型基于盲注的字符型Order By从句堆叠注入)

    http://192.168.136.128/sqli-labs-master/Less-53/?sort=1';insert into users(id,username,password) val ...

  6. ESX/ESXi 主机的某些存储阵列可能存在读取或写入性能问题 (1002598)

    Last Updated: 12/14/2018Categories: Troubleshooting  Details 免责声明:本文为 ESX/ESXi hosts might experienc ...

  7. webpack打包出错,通过babel将es6转es5的出错。

    错误信息如下: 解决方法: 1,先安装babel-preset-es2015到项目中, cnpm install babel-preset-es2015 --save-dev2,在项目根目录中新建一个 ...

  8. css3部分注意事项

    CSS 选择符有哪些?哪些属性可以继承?优先级算法如何计算? CSS3新增伪类有那些? 1.选择器 id选择器( # myid) 类选择器(.myclassname) 标签选择器(div, h1, p ...

  9. (C/C++学习)7.数组及其访问方式

    说明:数组的数据类型是一种构造类型,而存储数组的内存是一段连续的存储区域.数组的数据类型决定了连续内存的访问方式,它包括数组的三要素:起始地址.步长以及元素个数. 一.一维数组 1.形式:type 数 ...

  10. 使用python的几个小经验(查看文档)

    好久没有水博客了,未来再过20天不到的时间又得参加软考,今天终于得好好水一发帖子 关于Python,很多人包括我之前都不知道怎么找文档,现在有一个好办法,就是在命令行模式下调用pydoc –p xxx ...