Function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1025    Accepted Submission(s): 457

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 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.

 
Input
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.

 
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
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6044 6043 6042 6041 6040 

题意:
给出两个序列,一个是0~n-1的排列a,另一个是0~m-1的排列b,现在求满足的f的个数。

思路:

找到a序列中的循环节个数,并且记录每个循环节中有多少因子,b序列同理

如果a中的某个循环节里面因子的个数能整除 b中某个循环节的因子个数,那就加上b的这个循环节因子的个数

最后乘起来就是结果,

然而一脸懵逼,传说中的高等线代。。。。。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<bits/stdc++.h> using namespace std;
const long long mod=1e9+;
int n,m;
int a[],b[],a1[],b1[];
bool vis[];
int acir,bcir;
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(vis,,sizeof(vis));
acir=;
for(int i=;i<n;i++)
{
if (vis[i]) continue;
int k=i;
acir++; a1[acir]=;
while(!vis[k])
{
vis[k]=;
a1[acir]++;
k=a[k];
}
}
bcir=;
memset(vis,,sizeof(vis));
for(int i=;i<m;i++)
{
if (vis[i]) continue;
int k=i;
bcir++; b1[bcir]=;
while(!vis[k])
{
vis[k]=;
b1[bcir]++;
k=b[k];
}
}
long long ans=;
for(int i=;i<=acir;i++)
{
long long tmp=;
for(int j=;j<=bcir;j++)
if (a1[i]%b1[j]==) tmp+=b1[j];
ans=ans*tmp%mod;
}
printf("Case #%d: %lld\n",++cas,ans%mod);
}
return ;
}

hdu 6038 Function的更多相关文章

  1. HDU 6038 - Function | 2017 Multi-University Training Contest 1

    /* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...

  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 ...

  3. HDU 6038 Function(思维+寻找循环节)

    http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意:给出两个序列,一个是0~n-1的排列a,另一个是0~m-1的排列b,现在求满足的f的个数. 思路: ...

  4. 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 ...

  5. HDU 6038 Function —— 2017 Multi-University Training 1

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total ...

  6. HDU 5608 function [杜教筛]

    HDU 5608 function 题意:数论函数满足\(N^2-3N+2=\sum_{d|N} f(d)\),求前缀和 裸题-连卷上\(1\)都告诉你了 预处理\(S(n)\)的话反演一下用枚举倍数 ...

  7. HDU 5608 - function

    HDU 5608 - function 套路题 图片来自: https://blog.csdn.net/V5ZSQ/article/details/52116285 杜教筛思想,根号递归下去. 先搞出 ...

  8. 洛谷P1464 Function  HDU P1579 Function Run Fun

    洛谷P1464 Function HDU P1579 Function Run Fun 题目描述 对于一个递归函数w(a,b,c) 如果a≤0 or b≤0 or c≤0就返回值11. 如果a> ...

  9. 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 ...

随机推荐

  1. iframe跨页面调用函数

    在项目中难免会遇到这样一个问题就是页面引入了IFrame并且需要父页面调用子页面函数或者子页面需要调用父页面函数.比如说:现在有两个页面parent.html和child.html.其中parent. ...

  2. RocEDU.阅读.写作《苏菲的世界》书摘(四)

    亚理斯多德认为,快乐有三种形式.一种是过着享乐的生活,一种是做一个自由而负责的公民,另一种则是做一个思想家与哲学家.接着,他强调,人要同时达到这三个标准才能找到幸福与满足. 亚理斯多德提倡所谓的&qu ...

  3. 20145329 《Java程序设计》第七周学习总结

    教材学习内容总结 +JDK出现之前就已经存在的java.util.Date与java.util.Calendar等API +如果想取得系统时间,方法之一是使用System.currentTimeMil ...

  4. 20135320赵瀚青LINUX内核分析第三周学习笔记

    赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 概述 本周是学习的主要是构造 ...

  5. 【纯代码】Swift-自定义PickerView单选(可修改分割线颜色、修改字体大小、修改字体颜色。)(可根据需要自己扩展)

    typealias PopPickerViewCallBackClosure = (_ resultStr:NSString?) -> () class PopPickerView : UIVi ...

  6. lua5.3中luaL_setfunc设置upvalue的用法示例

    缘起 luaL_setfuncs 这个函数可以注册c函数到lua,另外还可以设置闭包函数使用的变量upvalue. 我没有用过,在 云风的skynet 才第一次见过,于是写个例子实际使用以下. 函数原 ...

  7. git gc内存错误的解决方案

    Auto packing the repository for optimum performance. You may alsorun "git gc" manually. Se ...

  8. ssm中不能访问静态资源问题

    最近用springmvc spring mybatis框架写程序,请求成功并获得数据,唯独css样式不能加载,但路径正确,css文件编码也是utf-8,用火狐debug总是显示未请求到(都快怀疑自己写 ...

  9. HTTP协议中的COOKIE机制简单理解

    1.为什么会有COOKIE这种机制 首先一种场景, 在一个网站上面, 我发起一次请求,那服务器怎么知道我是谁?是谁发起的这次请求呢, HTTP协议是无状态的协议, 浏览器的每一次请求,服务器都当做一次 ...

  10. Spring MVC 实践笔记

    1.了解 Maven 的用法:http://spring.io/guides/gs/maven/ .这篇英文非常详细的演示了 Maven 的用法,在命令行下执行.注意,运行Maven的时候,Maven ...