学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸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 ;
}

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

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

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

 
 
 

最新文章

  1. [虾扯蛋] android界面框架-Window
  2. 详解 IOS 7.1 程序启动原理
  3. 用Backbone.js创建一个联系人管理系统(三)
  4. jquery扩展函数详解(我的人生颠覆)
  5. .NET 通过SmtpClient发送邮件 提示 4.7.1 service unavailable try again later 解决办法
  6. [Bootstrap] 2. class &#39;row&#39; &amp; &#39;col-md-x&#39; &amp; &#39;col-md-offset-x&#39;
  7. JAVA GUI学习 - 窗体背景图片设置方法:重写paintComponent(Graphics g)方法
  8. SQL 默认数据库被误删
  9. Spring.net 学习IOC------属性注入
  10. hibernate的一级和二级缓存
  11. Visual Studio 2010多线程编程
  12. dubbo could not get local host ip address will use 127.0.0.1 instead 异常处理
  13. How to enable AHCI on Windows7
  14. zabbix在ubuntu16.04上的安装
  15. Fiddler抓包6-get请求(url详解)
  16. 扫盲记-第六篇--Normalization
  17. 重写&amp;重载
  18. Docker:集装箱式“运输”在软件上的实现
  19. H5音乐播放器源码共享
  20. ASP.NET MVC3控制器传递匿名对象到视图实例

热门文章

  1. erlang连接mysql [转]
  2. 软引用SoftReference
  3. Unicode字符图标
  4. 嵌入式(Embedded System)笔记 —— Cortex-M3 Introduction and Basics(上)
  5. USACO Section1.5 Prime Palindromes 解题报告
  6. Python列表深浅复制详解
  7. 六 APPIUM Android 定位方式
  8. web浏览器中的javascript -- 2
  9. Thread suspend()挂起resume()恢复
  10. 有许多部分没有在cgroup中显示啊,current/high/low/min等等