BNU16494:Kinds of Fuwas
来源:互联网 发布:在线客服软件有哪些 编辑:程序博客网 时间:2024/05/21 11:06
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
题意:统计四角相等的矩形又几个
思路:枚举即可,先预定好矩形上边的左右端点,再一行行往下推,看以一样的符号位端点有几个,再用公式n*(n-1)/2统计这些能组成几个矩形,然后相加
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int find(char c){ if(c == 'B') return 1; if(c == 'J') return 2; if(c == 'H') return 3; if(c == 'Y') return 4; if(c == 'N') return 5;}int s[10];char map[255][255];int main(){ int t,n,m,i,j,k,ans; scanf("%d",&t); while(t--) { ans = 0; scanf("%d%d",&n,&m); for(i = 0; i<n; i++) scanf("%s",map[i]); for(i = 0; i<m; i++) { for(j = i+1; j<m; j++) { memset(s,0,sizeof(s)); for(k = 0; k<n; k++) { if(map[k][i] == map[k][j]) { int r = find(map[k][i]); s[r]++; } } for(k = 1; k<=5; k++) ans+=s[k]*(s[k]-1)/2; } } 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【思维】
- JavaIO之创建文件(一)
- timus 1268 原根
- 多线程入门(Time to step into multi-threading)
- 创建完美的表DataTable和Jeditable的jQuery插件
- JDBC实现文件、图片的存储实例
- BNU16494:Kinds of Fuwas
- 收取金额查询—日历控件&查询两个日期之间的数据
- ssh到CentOS6.4,打开firefox,codeblocks等使用中文输入法设置(亲自验证有效)
- oracle decode
- Rotate List
- 初识python
- perl脚本自动化控制之android模拟器
- 编辑单个CPP文件,出现1>LIBCMTD.lib(crt0.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函
- JavaIO之RandomAccessFile(一)