2017多校1 1006Function
来源:互联网 发布:微博域名修改 编辑:程序博客网 时间:2024/05/24 05:55
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1530 Accepted Submission(s): 720
Problem Description
You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1 .
Define that the domain of functionf is the set of integers from 0 to n−1 , and the range of it is the set of integers from 0 to m−1 .
Please calculate the quantity of different functionsf satisfying that f(i)=bf(ai) for each i from 0 to n−1 .
Two functions are different if and only if there exists at least one integer from0 to n−1 mapped into different integers in these two functions.
The answer may be too large, so please output it in modulo109+7 .
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
Input
The input contains multiple test cases.
For each case:
The first line contains two numbersn, m .(1≤n≤100000,1≤m≤100000)
The second line containsn numbers, ranged from 0 to n−1 , the i -th number of which represents ai−1 .
The third line containsm numbers, ranged from 0 to m−1 , the i -th number of which represents bi−1 .
It is guaranteed that∑n≤106, ∑m≤106 .
For each case:
The first line contains two numbers
The second line contains
The third line contains
It is guaranteed that
Output
For each test case, output "Case #x :y " in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
3 21 0 20 13 42 0 10 2 3 1
Sample Output
Case #1: 4Case #2: 4
给2组数求不同函数关系的种类,根据题目的意思,就是求2组数列中不同环的数量,因为根据多对一的关系,将第二个数组中将 是第一个数组中不用数量的环的因子数的环相加,再最终将结果相乘即可。可以用vector容器来存不同数量的环
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<iomanip>#include<queue>#include<vector>using namespace std;const long long int MOD=7+1e9;vector<int> al,bl;int a[111111],b[111111];bool v[111111];int main(){ int n,m; int cs=0; ios::sync_with_stdio(false); while(cin>>n>>m) { al.clear(); bl.clear(); int i; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<m;i++) cin>>b[i]; memset(v,0,sizeof(v)); for(i=0;i<n;i++) { if(!v[i]) { int now=a[i]; int len=0; while(!v[now]) { v[now]=1; len++; now=a[now]; } al.push_back(len); } } memset(v,0,sizeof(v)); for(i=0;i<m;i++) { if(!v[i]) { int now=b[i]; int len=0; while(!v[now]) { v[now]=1; ++len; now=b[now]; } bl.push_back(len); } } int j; long long int ans=1; for(i=0;i<al.size();i++) { long long int ans1=0; for(j=0;j<bl.size();j++) if(al[i]%bl[j]==0) ans1=(ans1+bl[j])%MOD; ans=(ans*ans1)%MOD; } cout<<"Case #"<<++cs<<": "; cout<<ans%MOD<<endl; } return 0;}
阅读全文
0 0
- 2017多校1 1006Function
- 2017多校2 1006 Funny Function
- 2017 多校 Function(置换群
- HDU 6038 Function (多校1)
- HDU-2017 多校训练赛1-1006-Function
- hdu6038-思维-2017多校(2)-Function
- 2017多校第一场 1006 Function
- 2017第一次多校联合 1006Function
- HDU 6038 Function (2017多校1 -- 找循环节计数)
- HDU 6038 (2017 多校训练赛1 1006) Function(图论)
- HDU_【2017 Multi-University Training Contest 1】———1006 Function
- 多校6050 Funny Function
- 2017杭电多校联赛-Function
- function object (functor) (1)
- JavaScript--function()(1)
- Javascript 笔记(1)----Function
- javascript:Function笔记1
- Javascript Learning Function(1)
- Ubuntu的Samba服务,实现Windows映射网络盘到Ubuntu
- python 关于协程的二三事
- linux服务器查看防火墙状态
- laravel资源路由
- mysql使用临时量排序
- 2017多校1 1006Function
- python os.path 骚操作
- What is a NullPointerException?
- x的n次幂
- 猜数游戏
- E
- CodeForces B. Karen and Coffee
- 操作EEPROM时触发ECC内部故障导致通信失败
- codeforces731F (思维)