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) 代码 ...
随机推荐
- 不缓存JS
方法一:告诉浏览器不要缓存(不一定好使) <meta http-equiv="Pragma" content="no-cache"> <met ...
- python实现堆栈与队列的方法
python实现堆栈与队列的方法 本文实例讲述了python实现堆栈与队列的方法.分享给大家供大家参考.具体分析如下: 1.python实现堆栈,可先将Stack类写入文件stack.py,在其它程序 ...
- Vagrant 手册之多个虚拟机 multi-machine
原文地址 Vagrant 可以通过一个 Vagrantfile 定义并控制多个客户机.这就是所谓的"multi-machine"多虚拟机环境. 这些机器通常可以协同工作,或者互相关 ...
- Mac环境搭建nginx服务器
一 安装 1 安装Homebrew macOS 缺失的软件包的管理器,安装方法参考官网.(可能被墙) 2 安装nginx. brew install nginx 先更新homebrew.再安装ngin ...
- Codeforces - 1194F - Crossword Expert - 组合数学
https://codeforc.es/contest/1194/problem/F 下面是错的. 看起来有点概率dp的感觉? 给你T秒钟时间,你要按顺序处理总共n个事件,每个事件处理花费的时间是ti ...
- 32.Group Anagrams(相同元素的不同组合)
Level: Medium 题目描述: Given an array of strings, group anagrams together. Example: Input: ["eat ...
- vue-cli3脚手架的安装
如果之前有安装过其他的版本的话,要先卸载 卸载:npm uninstall vue-cli-g 或 yarn global remove vue-cli 安装:npm i @vue/cli -g ...
- CSS样式表能否控制文字禁止选择,复制, 焦点
div中禁止文字被选择 在做div的点击计数事件时,遇到一个小问题. 因为div里面有文字,所以当点击多次时,特别是鼠标点的比较快的时候,文字会被选中. 查了下,用css和javascript可以实现 ...
- Xcode 及 iOS 常用宏和常量
Xcode Xcode 工程设置支持 bash 脚本及其语法,如 $(PROJECT_DIR)$(PROJECT_DIR) PROJECT_DIR 代表当前工程的绝对路径,所以 $(PROJECT_D ...
- 140-基于双TI DSP TMS320C6670+XC7K480T的6UCPCI Express高速数据处理平台
基于双TI DSP TMS320C6670+XC7K480T的6UCPCI Express高速数据处理平台 一.板卡概述: 本技术开发主要是支持客户完成基于TI DSP TMS320C6678芯片和X ...