hdu 6038 Function
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1025 Accepted Submission(s): 457
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.
题意:
给出两个序列,一个是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的更多相关文章
- 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的个数. 思路: ...
- 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 —— 2017 Multi-University Training 1
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...
- HDU 5608 function [杜教筛]
HDU 5608 function 题意:数论函数满足\(N^2-3N+2=\sum_{d|N} f(d)\),求前缀和 裸题-连卷上\(1\)都告诉你了 预处理\(S(n)\)的话反演一下用枚举倍数 ...
- HDU 5608 - function
HDU 5608 - function 套路题 图片来自: https://blog.csdn.net/V5ZSQ/article/details/52116285 杜教筛思想,根号递归下去. 先搞出 ...
- 洛谷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> ...
- 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 ...
随机推荐
- 【android】activity的4种启动模式简介
首先咱必须知道,activity是以栈(后进先出)的结构进行管理的. 当活动A启动了活动B时,A被压入到栈内,B在栈的最顶层.当B调用finish()结束活动时,B从栈弹出,此时A在栈的最顶层. 我们 ...
- 【npm】使用淘宝提供的镜像来加速npm
国外的npm用着非常不稳定,时常一直就卡在安装的进度条上 淘宝提供了一个国内镜像,保障了安装网络环境的稳定,和源地址10分钟同步一次,没有被收录的包会自动切换到npm官方下载,并添加进镜像库. 地址: ...
- vector 迭代 删除指定的元素
std::vector< Bullet * > m_vBullets; std::vector< Bullet * > m_vRemoveBulltes; ){ for ( s ...
- java 2017/6/26杂记
mkdirs()可以建立多级文件夹, mkdir()只会建立一级的文件夹, 如下: new File("/tmp/one/two/three").mkdirs(); 执行后, 会建 ...
- 为什么iterator,foreach遍历时不能进行remove操作?除了一种情况可以这样(特殊情况)?
Exception in thread "main" java.util.ConcurrentModificationException 并发修改异常引发的思考! 1 foreac ...
- Object的各种方法
Object的一些知识点总结 1.hasOwnProperty obj.hasOwnProperty(prop) 参数 prop: 要检测的属性字符串名称或者Symbol 返回值 用来判断一个对象是否 ...
- IO多路复用客户端-服务器模型
IO多路复用服务器 -- 实现字符回射 服务器端 /************************************************************************* ...
- shell编程(二)
case判断 前面了解了shell编程的if判断,其实除了if判断,还有case判断. case语法: case VAR in case1) command1 ;; case2) command2 ; ...
- excel日期插件
效果图 Private Sub DTPicker1_Click() ActiveCell.Value = DTPicker1.Value DTPicker1.Visible = False End S ...
- 【前端】jQuery选择器$()的实现原理
今天三七互娱技术面试的时候面试官问了我这个问题,当时一脸懵逼,于是好好总结一下. 当我们使用jquery选择器的时候,$(s).回默认去执行jquery内部封装好的一个init的构造函数每次申明一个j ...