HDU 6038 Function(找规律)——2017 Multi-University Training Contest
来源:互联网 发布:问道法宝混沌钟数据 编辑:程序博客网 时间:2024/05/24 06:32
传送门
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1034 Accepted Submission(s): 464
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 2
1 0 2
0 1
3 4
2 0 1
0 2 3 1
Sample Output
Case #1: 4
Case #2: 4
题目大意:
给定两个数列
解题思路:
其实题解说的很明白了,我就不在赘述了。
其实可以根据第二个样例找规律,然后大胆猜想,不用验证。
代码:
#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;}
阅读全文
1 0
- HDU 6038 Function(找规律)——2017 Multi-University Training Contest
- hdu 6038 找规律 置换 2017 Multi-University Training Contest
- HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest
- HDU 5826 physics(积分 找规律)——2016 Multi-University Training Contest 8
- HDU 5399 Too Simple(数学 + 找规律)——2015 Multi-University Training Contest 9
- HDU 5351 MZL's Border(大数 + 找规律)——2015 Multi-University Training Contest 5
- 2017 Multi-University Training Contest 10 1002 Array Challenge HDU 6172(找规律 矩阵快速幂)
- HDU 5754 Life Winner Bo(找规律 + 威佐夫博弈)--2016 Multi-University Training Contest 3
- HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3
- HDU 6050 Funny Function(构造矩阵+推公式)——2017 Multi-University Training Contest
- 2017 Multi-University Training Contest 1 && HDOJ 6038 Function 【强连通找环】
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- HDU 5810 Balls and Boxes(打表找规律)——2016 Multi-University Training Contest 7 1002
- HDU 6055 Regular polygon(计算几何+思维)——2017 Multi-University Training Contest
- HDU 6053 TrickGCD(分块+容斥)——2017 Multi-University Training Contest
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- HDU 6128 Inverse of sum(数论)——2017 Multi-University Training Contest
- HDU 3068 2017 Multi-University Training Contest
- CVPR 2017论文解读:特征金字塔网络FPN
- Freemarker中如何遍历List及控制循环次数
- 使用类路径加载资源文件
- node.js学习笔记之Buffer类
- SPOJ New Distinct Substrings(后缀数组)
- HDU 6038 Function(找规律)——2017 Multi-University Training Contest
- bitset [HZOI 2016]动物城的鸳鸯蛋传说
- 不想张口无言,请学会独立思考
- 二维数组中的查找
- Android开发知识(四)Android进程间Binder通信机制的源码分析(下)
- centOS防火墙iptables的设置教程
- 大型网站架构系列:负载均衡详解(4)
- PDF编辑技巧2:设置页眉页脚和添加页码
- ubuntu下安装Redmine项目管理工具