Codeforces 757 C Felicity is Coming! 【STL+思维】
2017-08-21 22:48
423 查看
题意:已知有m种口袋精灵,n个体育场,每个体育场有g[i]个精灵(已知类别),现在要求进行精灵进化。进化的要求有:进化后,每个体育馆的精灵物种以及数量不能发生改变。问最多有多少种可能性。
思路:要满足,物种以及数量不改变的情况下,假定a进化为b,b进化为a。那么对于所有的体育馆来说,A的数量==B的数量。对于A、B精灵的出现集合一定要一一对应,不能多,不能少。
这样我们开个vector来存储每个动物出现的体育馆号。然后sort vector 使得长度相等并且所有元素都相等的vector 就是满足条件的情况。如果有n个连续成立的,那么可能性就是n! 。 然后求一下最后的结果,注意爆int和取mod
CODE:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+50;
const int MOD=1e9+7;
vector <int> a[maxn];
int main(void)
{
int n,m;
cin >> n >>m;
for(int i=1;i<=m;i++)
a[i].clear();
for(int i=1;i<=n;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int type;
scanf("%d",&type);
a[type].push_back(i);
}
}
sort(a+1,a+1+m);
/* for(int i=1;i<=m;i++)
{
printf("i=%d ",i);
for(int j=0;j<a[i].size();j++)
printf("%d ",a[i][j]);
}*/
ll ans=1,t=1;
for(int i=2;i<=m;i++)
{
if(a[i]==a[i-1]) t++,ans*=t%MOD,ans%=MOD;
else t=1;
}
cout << ans << endl;
}
思路:要满足,物种以及数量不改变的情况下,假定a进化为b,b进化为a。那么对于所有的体育馆来说,A的数量==B的数量。对于A、B精灵的出现集合一定要一一对应,不能多,不能少。
这样我们开个vector来存储每个动物出现的体育馆号。然后sort vector 使得长度相等并且所有元素都相等的vector 就是满足条件的情况。如果有n个连续成立的,那么可能性就是n! 。 然后求一下最后的结果,注意爆int和取mod
CODE:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+50;
const int MOD=1e9+7;
vector <int> a[maxn];
int main(void)
{
int n,m;
cin >> n >>m;
for(int i=1;i<=m;i++)
a[i].clear();
for(int i=1;i<=n;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int type;
scanf("%d",&type);
a[type].push_back(i);
}
}
sort(a+1,a+1+m);
/* for(int i=1;i<=m;i++)
{
printf("i=%d ",i);
for(int j=0;j<a[i].size();j++)
printf("%d ",a[i][j]);
}*/
ll ans=1,t=1;
for(int i=2;i<=m;i++)
{
if(a[i]==a[i-1]) t++,ans*=t%MOD,ans%=MOD;
else t=1;
}
cout << ans << endl;
}
相关文章推荐
- 【Codeforces 757 C Felicity is Coming! 】+ 思维
- Codeforces 757 C Felicity is Coming! 思维+STL
- codeforces 757 C. Felicity is Coming!
- CodeForces - 757C - Felicity is Coming!(思维)
- codeforces-757-【B、C思维】
- CodeForces - 808D(STL+思维)
- CodeForces - 540B School Marks (数学思维题 中位数)
- Codeforces 844C Sorting by Subsequences【思维】
- CodeForces - 361C A - Levko and Array Recovery 思维
- CodeForces - 798C Mike and gcd problem (贪心+思维)
- Codeforces - 558B. Amr and The Large Array - 计数+思维
- Codeforces 557B Pasha and Tea【二分+思维】
- codeforces 354A Vasya and Robot [思维]
- CodeForces 748C Santa Claus and Robot (思维)
- Codeforces 652B z-sort 【思维】
- Codeforces 918C - The Monster (贪心 + 思维 + 栈模拟)
- Codeforces 496 C Removing Columns【思维】
- Codeforces 593B Anton and Lines 【思维】【枚举】【排序】
- Codeforces 106D Treasure Island【思维+二维前缀和】
- codeforces 560 C. Gerald's Hexagon (思维,几何)