HDU6038-Function-数学+思维-2017多校Team01
学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸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 ;
}
学长的代码比我队友的快_(:з」∠)_
溜了溜了。不想喝拿铁咖啡。
加油加油_(:з」∠)_
HDU6038-Function-数学+思维-2017多校Team01的更多相关文章
- hdu6035[dfs+思维] 2017多校1
/*hdu6035[dfs+思维] 2017多校1*/ //合并色块, 妙啊妙啊 #include<bits/stdc++.h> using namespace std; ; const ...
- hdu6074[并查集+LCA+思维] 2017多校4
看了标答感觉思路清晰了许多,用并查集来维护全联通块的点数和边权和. 用另一个up[]数组(也是并查集)来保证每条边不会被重复附权值,这样我们只要将询问按权值从小到大排序,一定能的到最小的边权和与联通块 ...
- hdu6059[字典树+思维] 2017多校3
#include <bits/stdc++.h> using namespace std; typedef long long LL; * ][]; * ]; * ]; ][]; ; LL ...
- hdu6038[找规律+循环节] 2017多校1
/*hdu6038[找规律+循环节] 2017多校1*/ #include<bits/stdc++.h> using namespace std; typedef long long LL ...
- HDU 6038.Function-数学+思维 (2017 Multi-University Training Contest - Team 1 1006)
学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o 我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)... 数学+思维题,代码懂了,也能写出来,但是还是 ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- 2017 多校5 hdu 6093 Rikka with Number
2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...
- 程序设计中的数学思维函数总结(代码以C#为例)
最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...
- 「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 ...
随机推荐
- APP上传APP Store遇到的各种问题
内容含敏感话题或对苹果不友好的信息(如苹果婊) 使用了友盟的统计SDK,获取了IDFA但是上传填写无广告 采用友盟IDFA的sdk,并用友盟的默认淘宝页面广告,被告知和产品内容不符(最近) App在i ...
- Mybatis入门(一)之操作数据库
Whats Mybatis 持久层框架, 替代MVC层中DAO,因为DAO 层的需求就是 :能与数据库交互的对象. 能执行SQL语句. 不同于JDBC的connection,MyBatis 中有个Sq ...
- C++ 头文件系列(list)
简介 list实现的实际上是双向链表,所以叫它doubly-linked list也许更好. 因为实现的是双向链表,所以它有两个非常重要的性质: 双向 链表 双向 双向意味着----给定一个元素,我们 ...
- 童话故事 --- 什么是SQL Server Browser
高飞狗这几天特别郁闷,不知该如何通过TCP/IP协议连接SQL Server数据库.好在功夫不负有心人,经过几天的刻苦研究,终于得到了答案. 高飞狗呼叫UDP1434端口,"叮铃铃,叮铃铃- ...
- bzoj 2726: [SDOI2012]任务安排
Description 机 器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3...N.这N个任务被分成若干批,每批包含相邻的 若干任务.从时刻0开始,这 ...
- bzoj 1566: [NOI2009]管道取珠
Description Input 第一行包含两个整数n, m,分别表示上下两个管道中球的数目. 第二行为一个AB字符串,长度为n,表示上管道中从左到右球的类型.其中A表示浅色球,B表示深色球. ...
- HashMap 之弱引用 - WeakHashMap
■ Java 引用的相关知识 1. 强引用 Object o = new Object(); 强引用是Java 默认实现 的引用,JVM会尽可能长时间的保留强引用的存在(直到内存溢出) 当内存空间不足 ...
- linux下制作镜像文件
第一:制作iso镜像的方法: 把/dev/cdrom目录制作为镜像,名字为/root/rh1.iso 方法1:dd if=/dev/cdrom of=/root/rh1.iso 方法2:#cat /d ...
- (转) Linux中profile、bashrc、bash_profile之间的区别和联系
原文地址:http://blog.csdn.net/chenchong08/article/details/7833242 /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登 ...
- Ajax同源和跨域
ajax跨域访问 客户端页面 var url = "http://172.16.91.121:81/FellIn/FellIn.aspx?Action=WXSave&WX_Store ...