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 ...
随机推荐
- Ubuntu下pycharm设定任务栏图标后打开出现问号图标
事情是这样的: ubuntu16.04,安装好pycharm后,bin下只有一个sh执行文件,想要弄成任务栏图标,所以在/usr/share/applications下新建文件pycharm.desk ...
- java的String
String.valueOf() 将其他类型的值转换成字符串类型 String.intern() 该方法会将字符串常量池中的字符串与外部的字符串(s)进行比较,如果共享池中 ...
- app安全研究
国内Android App在线漏洞检测平台 腾讯金刚审计系统 http://service.security.tencent.com/kingkong 免费 无限制 腾讯御安全 http://yaq ...
- iOS开发之XMPPFramework开发基础介绍
1 使用iPhoneXMPP实例 2 修改xmppstream设置 3 基础协议的介绍 协议 协议简介 XEP-0009 在两个XMPP实体间传输XML-RPC编码请求和响应 XEP-0006 使能与 ...
- getAttribute() 与 attr() 的区别
getAttribute() 和 attr() 都是获取元素属性的方法,只是一种是 JS 写法,一种是 JQ 写法,但其实它们是有区别的. 主要区别 调用 getAttribute() 的主体必须是元 ...
- 有关string stringbuff stringbuild 的区别
string stringbuff stringbuild的执行效率: stringbuild>stringbuff>string String类是不可变类,任何对String的改变都会 ...
- SQL条件!=null查不出数据
今天有一条sql需要某两个字段不能为空,当然是不能为null也不能为空字符串啦. 然后就开始写 WHERE ( order_amount != null and order_amount != '' ...
- Vue数据绑定失效
首先,我们得明白Vue数据响应的原理: 以对象为例:当把一个JavaScript对象传给Vue实例的data选项时,Vue将遍历此对象所有的属性,并使用Object.defineProperty把这些 ...
- 20145313Java第一次实验
实验内容 1.JVM.JRE.JDK的安装位置与区别: 2.命令行运行javac:java:javac -cp; java -cp: 3.PATH,CLASSPATH,SOURCEPATH的设定方法与 ...
- RDB
在运行情况下, Redis 以数据结构的形式将数据维持在内存中, 为了让这些数据在 Redis 重启之后仍然可用, Redis 分别提供了 RDB 和 AOF 两种持久化模式. 在 Redis 运行时 ...