Kinds of Fuwas
来源:互联网 发布:天书世界坐骑进阶数据 编辑:程序博客网 时间:2024/05/21 14:45
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
22 2BBBB5 6BJHYNBBHBYYHBNBYNNJNBYNNBHBYYH
Sample Output
18
题解:暴力列举
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>using namespace std;int n,m;char e[255][255];int vis[255][255];int sovel(char ch){memset(vis,0,sizeof(vis));int i,j,k,h,cnt=1,ret=0;for(i=0;i<n-1;i++){for(j=0;j<m-1;j++){if(e[i][j]==ch){ //左上角坐标 for(k=j+1;k<m;k++){if(e[i][k]==ch && !vis[j][k]){ //右上角坐标 vis[j][k]=1;cnt=1;for(h=i+1;h<n;h++){ //找左下角坐标 if(e[h][j]==ch&&e[h][k]==ch) cnt++; //判断右下角坐标 }ret+=cnt*(cnt-1)/2;}}}}}//printf("%d***\n",ret);return ret;}int main(){int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(int i=0;i<n;i++){scanf("%s",e[i]);}int ans=0;ans=sovel('B')+sovel('J')+sovel('H')+sovel('Y')+sovel('N');printf("%d\n",ans);}return 0;}
- BNU16494:Kinds of Fuwas
- ZOJ2975 Kinds of Fuwas
- Kinds of Fuwas
- ZOJ2975-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 2975 Kinds of Fuwas
- ZOJ 2975Kinds of Fuwas
- 【简单数学】ZOJ 2975 Kinds of Fuwas
- zoj 2975 Kinds of Fuwas(数学题)
- Kinds of Fuwas(暴力+组合数学)
- ZOJ 2975Kinds of Fuwas(暴力)
- ZOJ 2975 Kinds of Fuwas【思维】
- HTTP协议详解
- Android Studio No Debuggable Applications
- Android控制水平方向字体缩放android:textScaleX
- matlab2014a中help与参考页翻译 find
- 分布式-基础之一-分布式系统调用
- Kinds of Fuwas
- 01.javascript中字符串常用操作总结、JS字符串操作大全
- 跨平台线程库——pThread
- 收录常用正则表达式
- 水池数目
- NYOJ - 喷水装置(二)
- iOS开发实战:如何将非ARC的项目转换成ARC项目
- 文章标题
- matlab2014a中help与参考页翻译 roots