HDU 6038 Function —— 2017 Multi-University Training 1
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1610 Accepted Submission(s): 755
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 1e9+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≤1e6, ∑m≤1e6.
1 0 2
0 1
3 4
2 0 1
0 2 3 1
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int MOD=1e9+;
const int MAXN=;
int a[MAXN],b[MAXN];
int la[MAXN],lb[MAXN];
bool vis[MAXN];
void dfsa(int t, int l, int *num){
if(vis[t]){
la[l]++;
return;
}
vis[t]=;
dfsa(num[t], l+, num);
}
void dfsb(int t, int l, int *num){
if(vis[t]){
lb[l]++;
return;
}
vis[t]=;
dfsb(num[t], l+, num);
}
int main()
{
int n,m,t=;
while(~scanf("%d%d", &n, &m))
{
for(int i=;i<n;i++)
scanf("%d", a+i);
for(int j=;j<m;j++)
scanf("%d", b+j);
memset(la, , sizeof(la));
memset(lb, , sizeof(lb)); memset(vis, , sizeof(vis));
for(int i=;i<n;i++)
if(!vis[i])
dfsa(i, , a); memset(vis, , sizeof(vis));
for(int i=;i<m;i++)
if(!vis[i])
dfsb(i, , b); int res=;
for(int i=;i<=n;i++){
if(la[i]){
int k=(int)(sqrt(i*1.0)+0.5),tmp=;
for(int j=;j<=k;j++){
if(i%j==){
tmp=(tmp+lb[j]*j%MOD)%MOD;
if(j*j!=i)
tmp=(tmp+lb[i/j]*(i/j)%MOD)%MOD;
}
}
for(int j=;j<la[i];j++)
res=res*tmp%MOD;
}
}
printf("Case #%d: %d\n", ++t, res);
}
return ;
}
嗯,是个图论题。
HDU 6038 Function —— 2017 Multi-University Training 1的更多相关文章
- HDU 6038 - Function | 2017 Multi-University Training Contest 1
/* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...
- HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9
/* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...
- 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
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 6170 - Two strings | 2017 ZJUT Multi-University Training 9
/* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问 ...
- HDU 6162 - Ch’s gift | 2017 ZJUT Multi-University Training 9
/* HDU 6162 - Ch’s gift [ LCA,线段树 ] | 2017 ZJUT Multi-University Training 9 题意: N节点的树,Q组询问 每次询问s,t两节 ...
- 2017 Chinese Multi-University Training, BeihangU Contest
2017 Chinese Multi-University Training, BeihangU Contest Add More Zero 思路:log10(2^m) = m*log10(2) 代码 ...
随机推荐
- Mac下隐藏或显示文件/文件夹
命令行操作 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults write com.apple.fi ...
- scrapy电影天堂实战(一)创建数据库
原文链接 这里的排版没微信公众号那么友好,建议查看公众号原文 创建数据库 首先我们需要创建数据库和表等来存储数据 创建mysql.cnf配置文件 oot@ubuntu:/mnt/test_scrapy ...
- Drone - 安装,搭配 GitLab 下的配置和使用
参考资料: Drone 官网地址:https://drone.io Drone 的 GitHub 地址:https://github.com/drone/drone 简介:https://imnerd ...
- Python笔记(十八)_私有属性、实例属性、类属性
私有属性 如果要让内部属性不被外部访问,可以把属性的名称前加上两个下划线__,就变成了一个私有属性,只有内部可以访问,外部不能直接访问或修改. 这样就确保了外部代码不能随意修改对象内部的状态,这样通过 ...
- Git013--多人协作
Git--多人协作 本文来自于:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ ...
- OSPF协议——原理及实验
首先命令部分: ospf 1 进入ospf协议 area 0 划定自治区域 因为实验只用了1个区域所以参数就为0 也就是骨干区域 network +网段+反写掩码(0.0.0.255)指定运行OSPF ...
- U盘修复教程--使用量产工具和芯片检测工具
U盘修复教程(金士顿DT101) 本教程使用量产工具(量产可理解为强制恢复出厂设置),量产有风险(U盘彻底报废),根据教程所造成所有损失均与本文作者无关. ·第一步:下载ChipGenius_v4_0 ...
- 基于vux的Vue路由切换动画
const history = window.sessionStorage history.clear() let historyCount = history.getItem('count') * ...
- JS formData
有时候,我们需要使用formData来上传文件,并根据反馈的结果做不同的处理, 这个时候使用form来提交文件不方便 #perform 获取的的上传文件所用的input标签 var formData ...
- nodejs启动
npm install cnpm install npm run dev cnpm install 与 npm install : https://blog.csdn.net/meng_suiga/ ...