HDU 6038 Function(找规律)——2017 Multi-University Training Contest - Team 1
2017-07-26 17:51
471 查看
传送门
Total Submission(s): 1034 Accepted Submission(s): 464
[align=left]Problem Description[/align] 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 function f 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 functions f 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 from 0 to n−1 mapped into different integers in these two functions.
The answer may be too large, so please output it in modulo 109+7.
[align=left]Input[/align] The input contains multiple test cases.
For each case:
The first line contains two numbers n, m. (1≤n≤100000,1≤m≤100000)
The second line contains n numbers, ranged from 0 to n−1, the i-th number of which represents ai−1.
The third line contains m numbers, ranged from 0 to m−1, the i-th number of which represents bi−1.
It is guaranteed that ∑n≤106, ∑m≤106.
[align=left]Output[/align] 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.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
题目大意:
给定两个数列 a 和 b, 求有多少个 f 映射满足: f(i)=bf(ai)
解题思路:
其实题解说的很明白了,我就不在赘述了。
其实可以根据第二个样例找规律,然后大胆猜想,不用验证。
代码:
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1034 Accepted Submission(s): 464
[align=left]Problem Description[/align] 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 function f 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 functions f 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 from 0 to n−1 mapped into different integers in these two functions.
The answer may be too large, so please output it in modulo 109+7.
[align=left]Input[/align] The input contains multiple test cases.
For each case:
The first line contains two numbers n, m. (1≤n≤100000,1≤m≤100000)
The second line contains n numbers, ranged from 0 to n−1, the i-th number of which represents ai−1.
The third line contains m numbers, ranged from 0 to m−1, the i-th number of which represents bi−1.
It is guaranteed that ∑n≤106, ∑m≤106.
[align=left]Output[/align] 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.
[align=left]Sample Input[/align]
3 2 1 0 2 0 1 3 4 2 0 1 0 2 3 1
[align=left]Sample Output[/align]
Case #1: 4 Case #2: 4
题目大意:
给定两个数列 a 和 b, 求有多少个 f 映射满足: f(i)=bf(ai)
解题思路:
其实题解说的很明白了,我就不在赘述了。
其实可以根据第二个样例找规律,然后大胆猜想,不用验证。
代码:
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <string.h> using namespace std; typedef long long LL; const int MAXN = 1e5+5; const LL MOD = 1e9+7; int vis[MAXN], A[MAXN], B[MAXN], a[MAXN], b[MAXN]; int get(int a[], int A[], int n){ memset(vis, 0, sizeof(vis)); int cnt = 0; for(int i=0; i<n; i++){ int cur = a[i]; if(!vis[cur]){ while(1){ if(vis[cur]) break; vis[cur] = 1; cur = a[cur]; A[cnt]++; } cnt++; } } return cnt; } int main() { int n, m, cas = 1; 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]); memset(A, 0, sizeof(A)); memset(B, 0, sizeof(B)); int cnta = get(a, A, n); int cntb = get(b, B, m); LL ans = 1; for(int i=0; i<cnta; i++){ LL cnt = 0; for(int j=0; j<cntb; j++) if(A[i]%B[j] == 0) cnt += B[j]; ans = ans * cnt % MOD; } printf("Case #%d: %lld\n",cas++,ans); } return 0; }
相关文章推荐
- 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
- HDU-6038 Function - 2017 Multi-University Training Contest - Team 1(构造置换或强连通分量)
- hdu 6038 找规律 置换 2017 Multi-University Training Contest - Team 1
- 2017 Multi-University Training Contest - Team 1(hdu 6038 Function)
- HDU 6038 - Function | 2017 Multi-University Training Contest 1
- HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest - Team 2
- 2017 Multi-University Training Contest - Team 2 :1006 Funny Function(找规律+逆元+快速幂取模)
- HDU-6129 Just do it - 2017 Multi-University Training Contest - Team 7(规律、杨辉三角、组合数奇偶性)
- 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】
- HDU-6105 Gameia - 2017 Multi-University Training Contest - Team 6(思维之找规律或二分图最大匹配)
- HDU 6050 Funny Function(构造矩阵+推公式)——2017 Multi-University Training Contest - Team 2
- hdu 6058 Kanade's sum(链表)(2017 Multi-University Training Contest - Team 3 )
- hdu 6070 Dirt Ratio(二分+线段树)(2017 Multi-University Training Contest - Team 4 )
- hdu 6071 Lazy Running(优先队列+dijkstra)(2017 Multi-University Training Contest - Team 4)
- hdu 6073 Matching In Multiplication(2017 Multi-University Training Contest - Team 4 )
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- hdu 6044 组合数+分治+模拟元 2017 Multi-University Training Contest - Team 1
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)