zoukankan      html  css  js  c++  java
  • 清北学堂模拟赛d3t1 a

    【问题描述】
    你是能看到第一题的friends呢。
    ——hja

    怎么快速记单词呢?也许把单词分类再记单词是个不错的选择。何大爷给出了一种分单词的方法,何大爷认为两个单词是同一类的当这两个单词的各个字母的个数是一样的,如dog和god。现在何大爷给了你 个单词,问这里总共有多少类单词。
    【输入格式】
    第一行一个整数N 代表单词的个数。
    接下来 N行每行一个单词。
    【输出格式】
    一行一个整数代表答案。
    【样例输入】
    3
    AABAC
    CBAAA
    AAABB
    【样例输出】
    2
    【数据范围与规定】

    分析:双Hash会被卡,毒瘤......把hash换成map就过了.把每个串各个字符的数量算出来,丢到map里,看之前有没有出现过就可以了.因为是结构体+map,所以需要重载<号.

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <map>
    
    using namespace std;
    
    int n,len,ans;
    
    struct node
    {
        int cnt[30];
        node()
        {
            memset(cnt, 0, sizeof(cnt));;
        }
        bool operator<(const node &a)const
        {
            for (int b = 1; b <= 26; b++)
                if (cnt[b] != a.cnt[b]) return cnt[b]<a.cnt[b];
            return false;
        }
    };
    
    char s[10000010];
    map<node, bool> m;
    
    int main()
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%s", s + 1);
            len = strlen(s + 1);
            node temp;
            for (int i = 1; i <= len; i++)
                temp.cnt[s[i] - 'A' + 1]++;
            if (!m[temp])
            {
                m[temp] = true;
                ans++;
            }
        }
        printf("%d
    ", ans);
    
        return 0;
    }
  • 相关阅读:
    bzoj1415 NOI2005聪聪和可可
    Tyvj1952 Easy
    poj2096 Collecting Bugs
    COGS 1489玩纸牌
    COGS1487 麻球繁衍
    cf 261B.Maxim and Restaurant
    cf 223B.Two Strings
    cf 609E.Minimum spanning tree for each edge
    cf 187B.AlgoRace
    cf 760B.Frodo and pillows
  • 原文地址:https://www.cnblogs.com/zbtrs/p/7625512.html
Copyright © 2011-2022 走看看