hdu 6038
来源:互联网 发布:虚拟屏幕软件 编辑:程序博客网 时间:2024/06/07 03:48
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1353 Accepted Submission(s): 623
Define that the domain of function
Please calculate the quantity of different functions
Two functions are different if and only if there exists at least one integer from
The answer may be too large, so please output it in modulo
For each case:
The first line contains two numbers
The second line contains
The third line contains
It is guaranteed that
3 21 0 20 13 42 0 10 2 3 1
Case #1: 4Case #2: 4
2017 Multi-University Training Contest - Team 1
题意:给出两个排列,a和b,求满足映射的f[i]=b_f[a[i]]的个数。
其实相当于排列b也是一个映射,把两个映射转化成两个图。
因为是1-n的排列,所以根据映射关系组成的一定是一个一个的环。
为了将f的映射和b的对应起来,对于f中的每个环,当b中的环的长度为f中的环的因数时,则可以匹配。最后再组合一下答案即可。
ac代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int mod = 1e9+7;
int n, m;
int a[maxn], b[maxn];
int vis[maxn];
vector<int> A;
vector<int> B;
int main()
{
//freopen("in.txt","r",stdin);
int kase=0;
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int i=0;i<m;i++) scanf("%d",&b[i]);
A.clear();
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
int cur=i,cnt=1;
if(!vis[i])
{
vis[i]=1;
while(a[cur]!=i)
{
cur=a[cur];
vis[cur]=1;
cnt++;
}
A.push_back(cnt);
}
}
B.clear();
memset(vis,0,sizeof(vis));
for(int i=0;i<m;i++)
{
int cur=i, cnt=1;
if(!vis[i])
{
vis[i]=1;
while(b[cur]!=i)
{
cur=b[cur];
vis[cur]=1;
cnt++;
}
B.push_back(cnt);
}
}
ll ans=1;
for(int i=0;i<A.size();i++)
{
ll tmp=0;
for(int j=0;j<B.size();j++)
{
if(A[i]%B[j]==0) tmp=(tmp+B[j])%mod;
}
ans=ans*tmp%mod;
}
printf("Case #%d: %d\n",++kase,ans);
}
return 0;
}
- 【HDU】6038
- hdu 6038
- HDU 6038 Function
- HDU-6038 Function
- hdu 6038 Function(思维)
- HDU 6038 Function
- hdu 6038 Function
- HDU 6038 Function
- hdu 6038 Function
- HDU 6038 Function
- Function (HDU 6038)
- HDU 6038 Function【思维】
- hdu--6038--Function
- HDU 6038-Function
- hdu 6038 Function
- HDU 6038 函数问题
- hdu 6038 Function
- Function HDU-6038
- 最小费用最大流基础模板(洛谷3381)
- HDU-1061-Rightmost Digit
- 2017 Multi-University Training Contest
- spfa+dp(洛谷1144 最短路计数)
- 并查集的离线搜索([JSOI2008]星球大战)
- hdu 6038
- 堆or优先队列(洛谷1801 黑匣子_NOI导刊2010提高(06))
- Python 模块搜索路径
- 求全排列的数学方法(洛谷1088 火星人noip2004普及组第4题)
- 全排列(洛谷1061 Jam的计数法or NOIP 2006 普及组 第三题)
- 快速幂+分治(洛谷P1045 麦森数 noip2003)
- shell脚本实现Linux日志服务配置Edition 2
- 模拟(洛谷1403 [AHOI2005]约数研究)
- Nginx配置子域名