Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming! 哈希

解法:对于pokermon a和b,只要它们在所有gym中出现的次数都是相同的,则变身的时候,种类可以互换。没有出现过的pokermon,归为所有gym都是0的情况,比赛的时候特判了这个反而没有过pretest。将数字划分到不同的集合内,则答案既是:(集合元素个数阶乘)的乘积。

用vector进行hash:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxm=1000005;
const ll mod=1e9+7;
vector<int> vec[maxm];
int n,m,t,c;
ll res,tc;
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;++i) {
        scanf("%d",&t);
        while (t--) {
            scanf("%d",&c);
            vec[c].push_back(i);
        }
    }
    sort(vec+1,vec+m+1);
    res=1;
    for (int i=1;i<=m;++i)
        if (vec[i]==vec[i-1]) {
            ++tc;
            res=(res*tc)%mod;
        } else
            tc=1;
    printf("%lld\n",res);
    return 0;
}

双哈希:

#include <bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
typedef long long ll;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
const ll mod1=1e9+7;
const ll mod2=1e9+3;
map<pll,ll> mp;
map<ll,ll> mp2[100005];
ll fac[1000006],pow1[100005],pow2[100005],ha1[1000005],ha2[1000005];
int n,m,a,t,tf;
int main()
{
    fac[0]=1LL;
    fac[1]=1LL;
    for (ll i=2;i<=1000005LL;++i)
        fac[i]=(i*fac[i-1])%mod;
    pow1[0]=1LL;
    pow2[0]=1LL;
    for (int i=1;i<=100000;++i) {
        pow1[i]=(mod1*pow1[i-1])%mod2;
        pow2[i]=(mod2*pow2[i-1])%mod1;
    }
    scanf("%d%d",&n,&m);
    map<ll,ll>::iterator it;
    for (int i=0;i<n;++i) {
        scanf("%d",&t);
        tf+=t;
        for (int j=0;j<t;++j) {
            scanf("%d",&a);
            ++mp2[i][a];
        }
        for (it=mp2[i].begin();it!=mp2[i].end();++it) {
            ha1[(*it).fst]=(ha1[(*it).fst]+(*it).snd*pow1[i])%mod2;
            ha2[(*it).fst]=(ha2[(*it).fst]+(*it).snd*pow2[i])%mod1;
        }
    }
    for (int i=1;i<=m;++i)
        ++mp[pll(ha1[i],ha2[i])];
    ll res=1LL;
    map<pll,ll>::iterator it2;
    for (it2=mp.begin();it2!=mp.end();++it2)
        res=(res*fac[(*it2).snd])%mod;
    printf("%lld\n",res);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值