zoukankan      html  css  js  c++  java
  • ZOJ Problem Set 2975 Kinds of Fuwas

    Kinds of Fuwas

    Time Limit: 1 Second      Memory Limit: 32768 KB

    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 Tconsecutive test cases.

    The first line of each test case has two integers M and N (1 <= MN <= 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
    

    Author: XUE, Zaiyue
    Source: The 5th Zhejiang Provincial Collegiate Programming Contest

    SOURCE CODE:

     


    #include<iostream>
    #include
    <vector>

    using namespace std;
    int main()
    {
    int cases;cin>>cases;
    while(cases--)
    {
    int x,y;cin>>x>>y;
    vector
    <vector<char> > martrix(x,vector<char>(y));
    for(int ix = 0;ix < x;ix++)
    for(int iy = 0; iy < y; iy++)
    cin
    >>martrix[ix][iy];
    int fumas = 0;
    for(int i = 0; i < x; i++)
    {
    for(int ii = i + 1; ii < x; ii++)
    {
    int b0 = 0, j0 = 0, h0 = 0, y0 = 0, n0 = 0;
    for(int k = 0; k < y; k++)
    {
    if(martrix[i][k] == martrix[ii][k])
    {
    switch(martrix[i][k])
    {
    case 'B':
    b0
    ++;
    break;
    case 'J':
    j0
    ++;
    break;
    case 'H':
    h0
    ++;
    break;
    case 'Y':
    y0
    ++;
    break;
    case 'N':
    n0
    ++;
    break;
    default:
    break;
    }
    }
    }
    fumas
    += (b0*(b0-1)/2 + j0*(j0-1)/2 + h0*(h0-1)/2 + y0*(y0-1)/2 + n0*(n0-1)/2);
    }
    }
    cout
    <<fumas<<endl;
    }
    }

    这题用搜索也能得到正确答案,但是会TLE。

  • 相关阅读:
    cmd启动数据库时,出现 (无法启动此程序,因为计算机中丢失VCRUNTIME140_1.dll 尝试重新安装此程序以解决此问题 )解决方法。
    浅谈Promise语法API+封装
    浅谈JS回调地狱
    MySQL数据库安装步骤
    将MongoDB安装为Windows服务---安装MongoDB服务
    后缀.msc文件是什么?
    Mongoose类库使用教程---实现增删改查
    MongoDB可视化工具--Robo 3T 安装使用教程
    久违的锻炼
    出差(2~十四)
  • 原文地址:https://www.cnblogs.com/malloc/p/2101771.html
Copyright © 2011-2022 走看看