ZOJ 2975Kinds of Fuwas
来源:互联网 发布:c语言左移运算符 编辑:程序博客网 时间:2024/05/21 13:55
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.
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.
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.
22 2BBBB5 6BJHYNBBHBYYHBNBYNNJNBYNNBHBYYH
18
直接考虑两行之间的合法矩形即可。
#include<map>#include<ctime>#include<cmath> #include<queue> #include<string>#include<vector>#include<cstdio> #include<cstring> #include<iostream>#include<algorithm> using namespace std;#define ms(x,y) memset(x,y,sizeof(x)) #define rep(i,j,k) for(int i=j;i<=k;i++) #define per(i,j,k) for(int i=j;i>=k;i--) #define loop(i,j,k) for (int i=j;i!=-1;i=k[i]) #define inone(x) scanf("%d",&x) #define intwo(x,y) scanf("%d%d",&x,&y) #define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z) typedef long long LL;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e3 + 10;int T, n, m, ans, c[5];char s[N][N], g[N];int main(){g['B'] = 0; g['J'] = 1; g['H'] = 2; g['Y'] = 3; g['N'] = 4;for (inone(T); T--;){intwo(n, m);rep(i, 1, n) scanf("%s", s[i] + 1);ans = 0;rep(i, 1, n){rep(j, i + 1, n){ms(c, 0);rep(k, 1, m) if (s[i][k] == s[j][k]) c[g[s[i][k]]]++;rep(k, 0, 4) ans += c[k] * (c[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浙江省赛】【暴力】
- HDU 3347 Calculate the expression(模拟 + map)
- Qt连接信号到子类槽函数提示父类无相应槽函数
- 107个基础常用JS语法大集合
- 数据库表的连接查询、子查询
- 安卓技能点说法
- ZOJ 2975Kinds of Fuwas
- 架构之美
- HDU1495:非常可乐
- sqlserver if exists 用法
- JSTL+EL与商品管理+分页显示
- 命令方式对Oracle数据库导入导出
- 求两个数的最小公倍数 比如输入2 3 输出6
- 优达学城优惠码 71C8FB5A
- 小小明_小小明手游框架_xxm_小小明手游平台