博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 6038.Function-数学+思维 (2017 Multi-University Training Contest - Team 1 1006)
阅读量:4318 次
发布时间:2019-06-06

本文共 2937 字,大约阅读时间需要 9 分钟。

 

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

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

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

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

 

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 n1 and a permutation b from 0 to m1.
Define that the domain of function f is the set of integers from 0 to n1, and the range of it is the set of integers from 0 to m1.
Please calculate the quantity of different functions f satisfying that f(i)=bf(ai) for each i from 0 to n1.
Two functions are different if and only if there exists at least one integer from 0 to n1 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(1n100000,1m100000)
The second line contains n numbers, ranged from 0 to n1, the i-th number of which represents ai1.
The third line contains m numbers, ranged from 0 to m1, the i-th number of which represents bi1.
It is guaranteed that n106, m106.
 

 

Output
For each test case, output "
Case #xy" 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的长度的数整除)。
但是我这里还不太懂为什么可以,队友给我讲的,明天继续研究,先写完题解滚去补作业。。。
 
代码直接看我队友的代码吧,我也是看的他的写的。传送门:
然后贴一下余学长的代码_(:з」∠)_ (别打我。。。)
 
代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 using namespace std;16 typedef long long ll;17 const int maxn=100000+10;18 const int mod=1e9+7;19 map
mp1,mp2;20 map
::iterator it1,it2;21 int a[maxn],b[maxn],vis[maxn];22 int n,m;23 void solve(int n,int *f,map
&mp)24 {25 memset(vis,0,sizeof(vis));26 int j,k;27 for(int i=0;i
first,t=it1->second;57 for(it2=mp2.begin();it2!=mp2.end();it2++)58 {59 int y=it2->first,num=it2->second;60 if(x%y==0)cnt=(cnt+y*num)%mod;61 }62 for(int i=1;i<=t;i++)63 ans=(ans*cnt)%mod;64 }65 printf("Case #%d: %lld\n",++kase,ans);66 }67 return 0;68 }

 

 

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

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

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

 
 
 

转载于:https://www.cnblogs.com/ZERO-/p/7788221.html

你可能感兴趣的文章
Linux安装Solr
查看>>
ActiveX安全
查看>>
js获取浏览器 尺寸信息
查看>>
/etc/inittab 学习
查看>>
xmpp IOS开发高级
查看>>
[转] - linux下使用write\send发送数据报 EAGAIN : Resource temporarily unavailable 错
查看>>
从0开始 图论学习 拓扑排序 链式前向星表示法
查看>>
centos6.5安装pip方法
查看>>
WCF常用绑定选择
查看>>
OGRE COMMAND-LINE UTILITIES
查看>>
IO:in、out和err
查看>>
Linux记录-使用python临时搭建web服务器
查看>>
日期转换为新数据类型CONVERT() 函数
查看>>
C#设计模式之十外观模式(Facade Pattern)【结构型】
查看>>
Redis进阶实践之十五 Redis-cli命令行工具使用详解第二部分(结束)
查看>>
Git使用gitignore建立项目过滤规则
查看>>
Can you solve this equation?
查看>>
经典算法50题
查看>>
广义距离变换
查看>>
2019年Q1总结+Q2大体规划
查看>>