HDU 6038.Function-数学+思维 (2017 Multi-University Training Contest - Team 1 1006)
学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸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
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.
#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)的更多相关文章
- 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 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)
学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memor ...
- HDU 6038 Function(思维+寻找循环节)
http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意:给出两个序列,一个是0~n-1的排列a,另一个是0~m-1的排列b,现在求满足的f的个数. 思路: ...
- HDU 6038 - Function | 2017 Multi-University Training Contest 1
/* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...
- 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 ...
- 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 ...
- 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 ...
- hdu 6038 Function
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 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 ...
随机推荐
- Android学习记录(5)—在java中学习多线程下载之断点续传②
在上一节中我们学习了在java中学习多线程下载的基本原理和基本用法,我们并没有讲多线程的断点续传,那么这一节我们就接着上一节来讲断点续传,断点续传的重要性不言而喻,可以不用重复下载,也可以节省时间,实 ...
- python学习笔记一:数据类型
一.Python文件类型 1.源代码 hello.py: 1 #!/usr/bin/python 2 print "hello world" 2.字节代码:python源文件经编译 ...
- 安装LoadRunner11报缺少vc2005_sp1_with_atl_fix_redist的错误
找到安装程序自带的lrunner\Chs\prerequisites\vc2005_sp1_redist,双击运行vcredist_x86.exe,再重新安装LoadRunner即可成功. 参考资料: ...
- 【Linux命令】删除大文件后磁盘空间未释放问题
前言 工作中经常遇到Linux系统磁盘空间不足,但是删除后较大的日志文件后,发现磁盘空间仍没有被释放,有点摸不着头脑,今天博主带大家解决这个问题. 思路 1.工作发现磁盘空间不足: 2.找到占用磁盘空 ...
- cloud-utils
官方下载:https://launchpad.net/cloud-utils rpm包下载地址:http://rpmfind.net/linux/rpm2html/search.php?query=c ...
- cloud-init代码调试方法
新做的centos7.4镜像的cloud-init安装好之后,修改密码失败,但是同样的配置文件在7.2上的是正常的,对比了一下版本,centos7.4上的是0.7.9,7.2上的是0.7.5,经过调试 ...
- LightGBM的并行优化--机器学习-周振洋
LightGBM的并行优化 上一篇文章介绍了LightGBM算法的特点,总结起来LightGBM采用Histogram算法进行特征选择以及采用Leaf-wise的决策树生长策略,使其在一批以树模型为基 ...
- Elasticsearch相关度评分_score
相关度评分 _score 的目的 是为了将当前查询的结果进行排序,比较不同查询结果的相关度评分没有太大意义. _score的计算方式 score(q,d) = # score(q,d) 是文档 d 与 ...
- 虚机中访问外网;NAT中的POSTROUTING是怎么搞的?
看下docker中是怎么配置的网络 在虚机中访问外网:设定了qemu,在主机上添加路由:sudo iptables -t nat -I POSTROUTING -s 192.168.1.110 -j ...
- 【NOI 2015网络同步赛】
今年没法去.. 分数160+181+100(假设我有去考笔试)=441 分数线:金548 银459 铜331 并没有到银牌线.... 以后题目啊数据啊出来的话继续更新 2015.7.19