zoj 2975 Kinds of Fuwas(数学题)
来源:互联网 发布:雅士尼处理器软件 编辑:程序博客网 时间:2024/05/21 17:02
转载请注明出处!谢谢!
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 <= 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
思路:公式: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(数学题)
- ZOJ 2975Kinds 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
- ZOJ 2975 Kinds of Fuwas【思维】
- Kinds of Fuwas ——zoj 2975
- 哈理工2015暑假集训 zoj 2975 Kinds of Fuwas
- ZOJ 2975-K - Kinds of Fuwas-暴力+bitset
- ZOJ-2975-Kinds of Fuwas【5th浙江省赛】【暴力】
- python数据结构与算法 6栈的应用之符号平衡(通用)
- 10400 - Game Show Math
- Sicily10359(优先队列)
- POJ 1195 Mobile phones
- LeetCode Best Time to Buy and Sell Stock II
- zoj 2975 Kinds of Fuwas(数学题)
- 12款很棒的浏览器兼容性测试工具推荐
- Handler的使用
- (libgdx学习)compass(指南针)
- 苹果帮助文档
- OllyDBG 入门系列(五)-消息断点及 RUN 跟踪
- 支持向量机的发展
- 图的邻接表表示
- 307 - Sticks