zoj 2975 Kinds of Fuwas(超时题)
2015-04-18 22:21
309 查看
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
Sample Output
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
2 2 2 BB BB 5 6 BJHYNB BHBYYH BNBYNN JNBYNN BHBYYH
Sample Output
1 8 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974 比赛的时候怎么就想不到这么简单的方法呢。。。#include<iostream> #include<algorithm> #include<string> #include<map> #include<vector> #include<cmath> #include<queue> #include<string.h> #include<stdlib.h> #include<cstdio> #define ll long long using namespace std; char x[251][251]; int main(){ int t; cin>>t; while(t--){ int n,m; cin>>n>>m; for(int i=0;i<n;++i){ for(int j=0;j<m;++j){ cin>>x[i][j]; } } int s=0; for(int i=0;i<n;++i){ for(int j=i+1;j<n;++j){ int a=0,b=0,c=0,d=0,e=0; for(int k=0;k<m;++k){ if(x[i][k]==x[j][k]){ if(x[i][k]=='B') a++; else if(x[i][k]=='J') b++; else if(x[i][k]=='H') c++; else if(x[i][k]=='Y') d++; else if(x[i][k]=='N') e++; } } s+=a*(a-1)/2+b*(b-1)/2+c*(c-1)/2+d*(d-1)/2+e*(e-1)/2; } } cout<<s<<endl; } return 0; }
相关文章推荐
- ZOJ 2975 Kinds of Fuwas(暴力+排列组合)
- ZOJ 2975 Kinds of Fuwas
- ZOJ 2975 Kinds of Fuwas(暴力)
- Kinds of Fuwas ——zoj 2975
- 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-K - Kinds of Fuwas-暴力+bitset
- 【简单数学】ZOJ 2975 Kinds of Fuwas
- ZOJ-2975-Kinds of Fuwas【5th浙江省赛】【暴力】
- zoj 2975 Kinds of Fuwas
- ZOJ Problem Set - 2975 Kinds of Fuwas
- ZOJ 2975 Kinds of Fuwas
- ZOJ 2975 Kinds of Fuwas
- ZOJ 2975 Kinds of Fuwas【思维】
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas
- BNU16494:Kinds of Fuwas
- K - Kinds of Fuwas----(2015 summer training #4 (Qualifying))