Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming! 哈希
来源:互联网 发布:webpackconfig.js 编辑:程序博客网 时间:2024/05/22 07:56
解法:对于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 secondtypedef 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;}
1 0
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming! 哈希
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C - Felicity is Coming!
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- C. Felicity is Coming! (STL水过)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!组合学+集合
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) A. Gotta Catch Em' All!(水题)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B - Bash's Big Day 枚举
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- B. Bash's Big Day (唯一分解定理)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day 数论+贪心
- Codeforces Round #391 -C. Felicity is Coming!
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day(分拆素因子+求最多的公因子)
- Codeforces Round #400 (Div. 1 + Div. 2, combined) C
- Codeforces Round #399 (Div. 1 + Div. 2, combined)C. Jon Snow and his Favourite Number
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- 168. Excel Sheet Column Title
- angular js 17年1月小结 (包括简单的指令和模块 服务等)
- 从web.xml入手分析jeecms配置文件
- 小数点位数的处理
- Linux Shell脚本去掉几类常见文件中的注释
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming! 哈希
- A Knight's Journey
- ios image not found
- Php基础语法
- Linu学习笔记之——ubuntu安装、卸载JDK1.7
- Spark的一些配置总结
- elasticsearch入门教程二(基于restful 针对5.1版本)
- 对不起,给不了你太多
- Android 使用CoordinatorLayout实现滚动标题栏效果