zoj 2975 Kinds of Fuwas
来源:互联网 发布:unity3d 沙盒fps源码 编辑:程序博客网 时间:2024/05/21 14:40
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;}
- ZOJ - 2975 Kinds of Fuwas
- zoj 2975 Kinds of Fuwas
- zoj 2975 Kinds of Fuwas
- ZOJ - 2975 Kinds of Fuwas
- ZOJ 2975 Kinds of Fuwas
- zoj 2975 Kinds of Fuwas
- zoj 2975 Kinds of Fuwas
- ZOJ 2975 Kinds of Fuwas
- ZOJ 2975Kinds of Fuwas
- 【简单数学】ZOJ 2975 Kinds of Fuwas
- zoj 2975 Kinds of Fuwas(数学题)
- ZOJ 2975Kinds of Fuwas(暴力)
- ZOJ 2975 Kinds of Fuwas【思维】
- Kinds of Fuwas ——zoj 2975
- zoj 2975 Kinds of Fuwas(超时题)
- 哈理工2015暑假集训 zoj 2975 Kinds of Fuwas
- ZOJ 2975-K - Kinds of Fuwas-暴力+bitset
- ZOJ-2975-Kinds of Fuwas【5th浙江省赛】【暴力】
- UITableView使用<1>之自定义UITableViewCell
- 文件传输基础——Java IO流
- ERROR 1045 (28000): Access denied for user 'hive'@'localhost' (using password: YES)
- 自动滚动的TextView
- CXF发送、接收消息超时设置
- zoj 2975 Kinds of Fuwas
- Linux TCP/IP大合集
- 关于mac原生系列设备【Mac mini、iMac、MB】,系统启动时键盘、鼠标均不能使用的解决方案
- android adb常用指令
- 设置了背景图片的TextView,其尺寸设置为wrap_content时,并不是适应文字内容大小
- NSSearchPathForDirectoriesInDomains用法
- 黑马程序员 break在Java中如何跳出多重嵌套循环
- 头晕眼花的Axure
- Uva-12166 Equilibrium Mobile