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

    枚举。

    枚举两行,然后算这两行之间有多少个矩形满足条件。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<ctime>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0);
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar();
        x = 0;
        while(!isdigit(c)) c = getchar();
        while(isdigit(c))
        {
            x = x * 10 + c - '0';
            c = getchar();
        }
    }
    
    int T,n,m;
    char s[300][300];
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&m);
            for(int i=0;i<n;i++) scanf("%s",s[i]);
            int ans=0;
            for(int i=0;i<n;i++)
            {
                for(int j=i+1;j<n;j++)
                {
                    int B=0,J=0,H=0,Y=0,N=0;
                    for(int k=0;k<m;k++)
                    {
                        if(s[i][k]=='B'&&s[j][k]=='B') B++;
                        if(s[i][k]=='J'&&s[j][k]=='J') J++;
                        if(s[i][k]=='H'&&s[j][k]=='H') H++;
                        if(s[i][k]=='Y'&&s[j][k]=='Y') Y++;
                        if(s[i][k]=='N'&&s[j][k]=='N') N++;
                    }
                    ans=ans+B*(B-1)/2+J*(J-1)/2+H*(H-1)/2+Y*(Y-1)/2+N*(N-1)/2;
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Python之格式化unix时间戳
    Python简单的验证码生成
    Python字符串常用的一些东西
    PHP explode()函数
    PHP函数number_format()
    PHP简单的计算位数的函数
    python之列表推导式
    python之把列表当做队列使用
    python之列表操作的几个函数
    python之map函数
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6407107.html
Copyright © 2011-2022 走看看