HDU 6038
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1034 Accepted Submission(s): 464
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.
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.
//可以看出f在定义域[0,n-1]中是循环的,f的每个循环节中只要有一个f的值确定了那么其他的f的值也就确定了(
//因为每相邻的两个f都相关),所以先找出a数列的所有的循环节然后在b中找f可以对应的值(同样是循环节),只有b
//的某个循环节是a的某个循环节的因子时这两个循环节才能匹配,统计能匹配的个数,结果相乘。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=;
const ll mod=1e9+;
int n,m,a[maxn],b[maxn];
int num1[maxn],num2[maxn];//num1[i]表示a数列第i个循环节的大小,num2[i]表示b数列长度为i的循环节的个数
int main()
{
int cas=;
while(scanf("%d%d",&n,&m)==){
for(int i=;i<n;i++) scanf("%d",&a[i]);
for(int i=;i<m;i++) scanf("%d",&b[i]);
memset(num2,,sizeof(num2));
memset(num1,,sizeof(num1)); int tot=;
for(int i=;i<n;i++){
if(a[i]==-) continue;
int ii=i;
tot++;
while(a[ii]!=-){
num1[tot]++;
int t=ii;
ii=a[ii];
a[t]=-;
}
}
for(int i=;i<m;i++){
if(b[i]==-) continue;
int ii=i,len=;
while(b[ii]!=-){
len++;
int t=ii;
ii=b[ii];
b[t]=-;
}
num2[len]++;
}
ll sum=;
for(int i=;i<=tot;i++){
ll cnt=;
for(int j=;j<=num1[i];j++){
if(num1[i]%j==){
cnt+=num2[j]*j;
cnt%=mod;
}
}
sum*=cnt;
sum%=mod;
}
printf("Case #%d: %lld\n",++cas,sum);
}
return ;
}
HDU 6038的更多相关文章
- HDU 6038 - Function | 2017 Multi-University Training Contest 1
/* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...
- 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU 6038 Function(思维+寻找循环节)
http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意:给出两个序列,一个是0~n-1的排列a,另一个是0~m-1的排列b,现在求满足的f的个数. 思路: ...
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
- 2017ACM暑期多校联合训练 - Team 1 1006 HDU 6038 Function (排列组合)
题目链接 Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m ...
- hdu 6038 Function
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU 6038.Function-数学+思维 (2017 Multi-University Training Contest - Team 1 1006)
学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o 我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)... 数学+思维题,代码懂了,也能写出来,但是还是 ...
- 【hdu 6038】Function
[Link]:http://codeforces.com/contest/834/problem/C [Description] 给你两个排列a和b; a排列的长度为n,b排列的长度为m; a∈[0. ...
- HDU 6038 Function —— 2017 Multi-University Training 1
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...
随机推荐
- hadoop2.7.1安装和部署
操作系统:Red Hat Enterprise Linux Server release 6.2 (Santiago) hadoop2.7.1 三台redhat linux主机,ip分别为10.204 ...
- 与面试官谈笑风生 | Python面向对象之访问控制
Python从设计之初就是一门面向对象的语言,面向对象思想的第一个要素就是封装.所谓封装,通俗的讲就是类中的属性和方法,分为公有和私有,公有可以被外界访问,私有不能被外界访问,这就是封装中最关键的概念 ...
- 关于解决MySort
关于解决MySort 那天老师教给我们关于sort的用法以及String类中的split方法.在一定程度上告诉我们sort用法的原理和一些特别的用法后,老师叫我们用JAVA尝试去设计一个"M ...
- 使用JSon实现三级联动
JSon实现三级联动 我觉得我这个方法比较麻烦,但是目前技术还比较弱,所以先做个笔记自己理解.目前没有和后台交互,只是在前台页面实现了 jQuery和JSon数据实现的,代码如下: <!DOCT ...
- HDU 5496 Beauty of Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5496 Beauty of Sequence Problem Description Sequence ...
- python处理时间相关的方法(汇总)
记录python处理时间的模块:time模块.datetime模块和calendar模块. python版本:2.7 在介绍模块之前,先说下以下几点: 1.时间通常有这几种表示方式: a.时间戳:通常 ...
- Iterable,Iterator和forEach
Iterable Interface Iterable<T> 方法: Iterator<T> iterator() Returns an iterator over a set ...
- sleep(),wait(),yield(),notify()
sleep(),wait(),yield() 的区别 sleep方法和yield方法是Thread类的方法,wait方法是Object的方法. sleep 方法使当前运行中的线程睡眼一段时间,进入不可 ...
- Docker 技术 介绍
https://github.com/docker/docker 实现用户空间隔离的技术:名称空间(NameSpace),CGroup(控制组) 什么是NameSpace::简单的理解就是,每一个虚拟 ...
- 对Excle的行和列进行检查 单元格类型转换代码 ;
对Excle的行和列进行检查 转换代码 : ** * 导入信息 */ @Override public List<Object> add(HttpServletRequest reque ...