学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o

我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)。。。

数学+思维题,代码懂了,也能写出来,但是还是有一点不懂,明天继续。

感谢我的队友不嫌弃我是他的猪队友(可能他心里已经骂了无数次我是猪队友了_(:з」∠)_ )

Function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2021    Accepted Submission(s): 956

Problem Description
You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1.

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.

 
Input
The input contains multiple test cases.

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.

 
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
 
Sample Input
3 2
1 0 2
0 1
3 4
2 0 1
0 2 3 1
 
Sample Output
Case #1: 4
Case #2: 4
 
Source
 
 
题意:吐槽啊,看不懂题意,后来推出来了,就是满足f(i)=bf(ai)这个式子。
函数套函数,假设a这个数组有5个数,那么就是f(0),f(1),f(2),f(3),f(4)这5个。
然后就是推。。。
对于f(0),i为0,i为a的下标,那么就是ai为a0,就是f(0)==bf(a0),然后看看a0对应的值是多少,这个值就是b的下标。就是这个意思。
然后就是,f这个函数值域是b数组中的任意一个数。假设a0对应的值是3,那么就是f(0)==bf(3)
f(3)的值是多少呢?就从b的数组中任选一个,如果这个数能够依次往下推,推到和最初的值相等就是符合条件的。推的这个过程就是一个循环节。
通过总结就可以发现,i和a数组有关,i和b数组也有关(和b有关的i不是和a有关的i),通过分别找出来a和b的循环节,就可以把个数相乘就是结果。
但是发现找循环节的时候,必须是b的循环节的长度是a的循环节的长度的约数才可以(就是b的长度这个数可以被a的长度的数整除)。
但是我这里还不太懂为什么可以,队友给我讲的,明天继续研究,先写完题解滚去补作业。。。
 
代码直接看我队友的代码吧,我也是看的他的写的。传送门:_(:з」∠)_
然后贴一下余学长的代码_(:з」∠)_ (别打我。。。)
 
代码:
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
typedef long long ll;
const int maxn=+;
const int mod=1e9+;
map<int,int>mp1,mp2;
map<int,int>::iterator it1,it2;
int a[maxn],b[maxn],vis[maxn];
int n,m;
void solve(int n,int *f,map<int,int> &mp)
{
memset(vis,,sizeof(vis));
int j,k;
for(int i=;i<n;i++)
{
j=i,k=;
while(!vis[j])
{
k++;
vis[j]=;
j=f[j];
}
if(k)
mp[k]++;
}
}
int main()
{
int kase=;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
for(int i=;i<m;i++)
scanf("%d",&b[i]);
mp1.clear();
mp2.clear();
solve(n,a,mp1);
solve(m,b,mp2);
ll ans=;
for(it1=mp1.begin();it1!=mp1.end();it1++)
{
ll cnt=,x=it1->first,t=it1->second;
for(it2=mp2.begin();it2!=mp2.end();it2++)
{
int y=it2->first,num=it2->second;
if(x%y==)cnt=(cnt+y*num)%mod;
}
for(int i=;i<=t;i++)
ans=(ans*cnt)%mod;
}
printf("Case #%d: %lld\n",++kase,ans);
}
return ;
}

学长的代码比我队友的快_(:з」∠)_

溜了溜了。不想喝拿铁咖啡。

加油加油_(:з」∠)_

 
 
 

HDU 6038.Function-数学+思维 (2017 Multi-University Training Contest - Team 1 1006)的更多相关文章

  1. 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 ...

  2. HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)

    学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others)    Memor ...

  3. HDU 6038 Function(思维+寻找循环节)

    http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意:给出两个序列,一个是0~n-1的排列a,另一个是0~m-1的排列b,现在求满足的f的个数. 思路: ...

  4. HDU 6038 - Function | 2017 Multi-University Training Contest 1

    /* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...

  5. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  6. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. 2017 Multi-University Training Contest - Team 1 1001&&HDU 6033 Add More Zero【签到题,数学,水】

    Add More Zero Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. hdu 6038 Function

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  9. 2017 Multi-University Training Contest - Team 2 &&hdu 6050 Funny Function

    Funny Function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. X的N次方。N比较大。

    final static long DIV = 1000000009; //分治法, 注意java类型为long, C++为__int64或 long long public static long ...

  2. springboot相关链接

    springboot的三种启动方式 https://blog.csdn.net/my__Sun_/article/details/72866329 springboot学历历程 https://www ...

  3. 更换checkbox的原有样式

    通常情况下,各个浏览器对的样式不一致,并且不那么美观.所以有时候设计需要我们更换原有的样式: html: <span><input type="checkbox" ...

  4. [GDOI2016] 疯狂动物园 [树链剖分+可持久化线段树]

    题面 太长了,而且解释的不清楚,我来给个简化版的题意: 给定一棵$n$个点的数,每个点有点权,你需要实现以下$m$个操作 操作1,把$x$到$y$的路径上的所有点的权值都加上$delta$,并且更新一 ...

  5. 绑定域名到 GitHub Pages

    简介 我在阿里云上注册了一个新域名:yuanzb.com,我已经在GitHub Pages上建立了自己的博客:http://yuanzb.github.io/yuanzb/.现在我希望将yuanzb. ...

  6. [poj] 2549 Sumsets || 双向bfs

    原题 在集合里找到a+b+c=d的最大的d. 显然枚举a,b,c不行,所以将式子移项为a+b=d-c,然后双向bfs,meet int the middle. #include<cstdio&g ...

  7. 2017 多校4 Wavel Sequence

    2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and ...

  8. 染色 color

    染色 color 题目描述 有一块矩阵平板,分成n*m个格子,一开始全是白色.在这上面进行k次染色,每次染色按照如下步骤:1. 随机选择一个格子,称为A.2. 随机选择一个格子,称为B.3. 将由A ...

  9. IE6对!important单个的类是支持的

    "!important"是什么? 第一个,是设置样式的优先级,设了!important的样式的属性优先于id选择器和class选择器.,比如id为"Main"的 ...

  10. HDU 5690 矩阵快速幂

    All X Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...