zoukankan      html  css  js  c++  java
  • 哈理工2015暑假集训 zoj 2975 Kinds of Fuwas

    G - Kinds of Fuwas
    Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu

    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 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

    2
    2 2
    BB
    BB
    5 6
    BJHYNB
    BHBYYH
    BNBYNN
    JNBYNN
    BHBYYH
    

    Sample Output

    1
    8
    
    当时训练赛的时候做的也比較麻烦,并没有非常成熟的思维去迅速组织搞笑代码。这是改进后的代码。
     
    #include<iostream>
    #include<sstream>
    #include<algorithm>
    #include<cstdio>
    #include<string.h>
    #include<cctype>
    #include<string>
    #include<cmath>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    using namespace std;
    const int INF=260;
    char cnt[INF][INF];
    int n,m;
    
    void before()
    {
        cin>>n>>m;
        for(int i=0; i<n; i++)
            scanf("%s",cnt[i]);
    }
    
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            before();
            int sum=0;
            for(int i=0; i<m-1; i++)//前两个for循环 控制列变换
            {
                for(int j=i+1; j<m; j++)
                {              
                    map< char ,int >dict;    //  统计每一个字母个数
                    set<char>xx;           //  统计字母种类
                    for(int k=0; k<n; k++) //控制行数
                    {
                        if(cnt[k][i]==cnt[k][j])
                        {
                            dict[cnt[k][j]]++;
                            xx.insert(cnt[k][j]);
                        }
                    }
                    set<char >::iterator it;
                    for(it=xx.begin(); it!=xx.end(); it++)
                    {
                        //如果某两列 出现n对同样的 则矩形数目为 n*(n-1)/2个
                        sum+=dict[*it]*(dict[*it]-1)/2;
                    }
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }
    
    


  • 相关阅读:
    BZOJ 1726: [Usaco2006 Nov]Roadblocks第二短路
    BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币
    BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
    BZOJ 1611: [Usaco2008 Feb]Meteor Shower流星雨
    BZOJ 1610: [Usaco2008 Feb]Line连线游戏
    BZOJ 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
    BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
    BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草
    BZOJ 1083: [SCOI2005]繁忙的都市
    STL set的用法
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7105449.html
Copyright © 2011-2022 走看看