2017 多校训练 1006 Function
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 273 Accepted Submission(s): 99
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.
1 0 2
0 1
3 4
2 0 1
0 2 3 1
Case #2: 4
/*
* @Author: Lyucheng
* @Date: 2017-07-25 15:25:56
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-07-25 20:42:28
*/
/*
题意:给你两个序列,定义一种函数 f(i)=b[f(ai)] ,问你已给出的序列可以构造出的函数的数量 思路:实际上就是从a集合到b集合的映射的组合,a中的一个循环节是一个整体,如果b中循环节的长度和a循环节的长度相同
或者是因子,那么就可以置换过来,满足这个条件,将结果组合一下就好 感悟:好气啊,想出来,但是没想到因子这个条件...
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define MAXN 100005
const long long MOD = 1e9+;
#define LL long long
using namespace std; int n,m;
int a[MAXN];
int b[MAXN];
bool visa[MAXN];
bool visb[MAXN];
vector<int> va;
vector<int> vb;
int ca=; void init(){
va.clear();
vb.clear();
memset(visa,false,sizeof visa);
memset(visb,false,sizeof visb);
memset(a,,sizeof a);
memset(b,,sizeof b);
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(scanf("%d%d",&n,&m)!=EOF){ init();
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<m;i++){
scanf("%d",&b[i]);
} for(int i=;i<n;i++){//求A的循环节
if(visa[i]==true) continue; int cur=;
int x=a[i];
while(x!=a[x]){
if(visa[x]==true) break;//走到了标记过的点 可能遇到没返回自己的循环了,也可能返回自己了
visa[x]=true;
cur++;
x=a[x];
}
if(x==a[i]){
if(cur==)
va.push_back();
else
va.push_back(cur);
}else{
va.push_back();
int cnt=;
while(x!=a[x]){
cnt++;
if(cnt>=cur) break;
visa[x]=false;
x=a[x];
}
visa[a[i]]=true;
}
} for(int i=;i<m;i++){//求B的循环节
if(visb[i]==true) continue; int cur=;
int x=b[i];
while(x!=b[x]){
if(visb[x]==true) break;//走到了标记过的点 可能遇到没返回自己的循环了,也可能返回自己了
visb[x]=true;
cur++;
x=b[x];
}
if(x==b[i]){
if(cur==)
vb.push_back();
else
vb.push_back(cur);
}else{
vb.push_back();
int cnt=;
while(x!=b[x]){
cnt++;
if(cnt>=cur) break;
visb[x]=false;
x=b[x];
}
visb[b[i]]=true;
}
} LL res=;
for(int i=;i<va.size();i++){
LL cur=;
for(int j=;j<vb.size();j++){
if(va[i]%vb[j]==){
cur+=( (LL)(vb[j]) ) %MOD;
cur%=MOD;
}
}
res=( (res%MOD) * (cur%MOD) )%MOD;
} printf("Case #%d: %d\n",ca++,res);
}
return ;
}
2017 多校训练 1006 Function的更多相关文章
- 「2017 Multi-University Training Contest 1」2017多校训练1
1001 Add More Zero(签到题) 题目链接 HDU6033 Add More Zero 找出最大的k,使得\(2^m-1\ge 10^k\). 直接取log,-1可以忽略不计. #inc ...
- 「2017 Multi-University Training Contest 2」2017多校训练2
1001 Is Derek lying 题目链接 HDU6045 Is Derek lying? 给出两个人选择题的回答,问得分分别为x和y是否可能.(\(1\le N \le 80000,0\le ...
- 2017 多校训练 1002 Balala Power!
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 「2017 Multi-University Training Contest 7」2017多校训练7
1002 Build a tree(递归) 题目链接 HDU6121 Build a tree 有一棵n个点的有根树,标号为0到n-1,i号点的父亲是\(\lfloor\frac{i-1}{k}\rf ...
- 「2017 Multi-University Training Contest 8」2017多校训练8
1009 I am your Father! (最小树形图-朱刘算法) 题目链接 HDU6141 I am your Father! 求有向图最大生成树,要求n的父节点尽量小. 我们将所有wi变为-w ...
- 【2017多校训练08 1002】【HDOJ 6134】Battlestation Operational
典型的数列反演题. 运用莫比乌斯反演的一个结论 $[n = 1] = \sum_{d | n} \mu(d)$,将表达式做如下转化: $$ ans = \sum_{i=1}^n \sum_{j=1}^ ...
- 【双向bfs】2017多校训练十 HDU 6171 Admiral
[题意] 现在给出一个三角矩阵,如果0编号的在点(x,y)的话,可以和(x+1,y),(x-1,y),(x+1,y+1),(x-1,y-1)这些点进行交换. 我们每一次只能对0点和其他点进行交换.问最 ...
- 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge
acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...
- 【(好题)组合数+Lucas定理+公式递推(lowbit+滚动数组)+打表找规律】2017多校训练七 HDU 6129 Just do it
http://acm.hdu.edu.cn/showproblem.php?pid=6129 [题意] 对于一个长度为n的序列a,我们可以计算b[i]=a1^a2^......^ai,这样得到序列b ...
随机推荐
- 在github上实现页面托管预览功能
1.建立个人github pages 仓库 创建新仓库,命名规则为----"你的github账号.github.io", 如图所示: 我的账号是zxpsuper,所以我的个人域名仓 ...
- 一款简洁而强大的前端框架JQUery—动画效果及剪刀石头布小游戏
jQuery是什么? jQuery是一个快速.简洁的JavaScript框架,它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作.事件处理.动画 ...
- 查找Oracle数据库中的重复记录
本文介绍了几种快速查找ORACLE数据库中的重复记录的方法. 下面以表table_name为例,介绍三种不同的方法来确定库表中重复的记录 方法1:利用分组函数查找表中的重复行:按照某个字段分组,找出行 ...
- Postman 串行传参和动态传参详解
Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件 用Postman做接口测试的时候,要把多条用例一起执行,就需要把用例连接起来,一次性执行 目录 串行传参 动态传参 使用 ...
- Html语言,使用<a>标签发送电子邮件
<a>标签有一个功能是可以链接Email地址,使用mailto能让访问者便捷向网站管理者发送电子邮件. 使用mailto 属性时请参考下表: 如果mailto里同时有多个参数,第一个参数必 ...
- Nginx学习——Nginx启动、停止、重启和信号控制以及平滑升级
1.Nginx 启动与停止 (1)启动方式 启动格式:Nginx可执行文件地址 -c Nginx配置文件地址 /etc/local/nginx/sbin/nginx -c /root/dufy/ngi ...
- PHP常用数组(Array)函数整理
整理了一份PHP开发中数组操作大全,包含有数组操作的基本函数.数组的分段和填充.数组与栈.数组与列队.回调函数.排序.计算.其他的数组函数等. 一.数组操作的基本函数 数组的键名和值 array_va ...
- MySQL Base
/* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 ---> input pwd /* 数据库存贮引擎 */ InnoDB : 1) ...
- HDU2089 暴力打表
62的判断就是倒过来没有26 hdu2089 #include<cstdio> #include<cstdlib> #include<iostream> #incl ...
- MVVM框架解析(一)
花了一点时间看了一下微软开源MVVM代码,受义很多! 从代码整体上看,代码分为四大类, 从图中看不能明白我要表达的意思.显而意见!MainApplicationWindow.xaml是应用程序主窗口( ...