Function这道题我当时一直很迷,到底怎么来的啊,为什么会这样啊??
然后看了题解才知道,原来是找循环啊。
已知f(i)=b[f(a(i)],则
f(0) = b[f(a[0])] = b[f(2)]
f[1] = b[f(a[1])] = b[f(0)]
f[2] = b[f(a[2])] = b[f(1)]
其实这道题可以转化为求环的问题,有多少种方式可以构成题目要求的环,即b的环可以有多少种方式画成a的环。
第一个样例我们可以知道 a0->a1->a0, a2->a2, b0->b0, b1->b1。
则和a同构的环有b0->b0->b0, b1->b1->b1, b0->b0, b1->b1四个
第二个样例我们可以知道a0->a2->a1->a0 b0->b0 b1->b2->b3->b1
则和a同构的环有b1->b2->b3->b1 b2->b3->b1->b2 b3->b1->b2->b3 b0->b0->b0->b0四个
然后找出所有环的长度,是a环的因子的就加起来,最后将所有的乘起来(为什么是乘起来??因为组合数学啊(●'◡'●))
ll ans=;
for (int i=; i<va.size(); i++) {
ll num=;
for (int j=; j<vb.size(); j++) {
if (va[i]%vb[j]==) num+=vb[j];
}
ans = ans*num%mod;
}
 代码:
/*  gyt
Live up to every day */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e5+;
const ll maxm = 1e7;
const ll mod = 1e9+;
const int INF = <<;
const db eps = 1e-;
int a[maxn], b[maxn];
bool visa[maxn], visb[maxn];
vector<ll>va, vb;
int ca=;
int flag;
void init() {
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(visa, , sizeof(visa));
memset(visb, , sizeof(visb));
va.clear();
vb.clear();
}
void solve() {
int n, m;
while(scanf("%d%d", &n, &m)!=EOF) {
init();
for (int i=; i<n; i++) {
scanf("%d", &a[i]);
}
for (int i=; i<m; i++) {
scanf("%d", &b[i]);
}
for (int i=; i<n; i++) {
if (visa[i]) continue;
int x=i; int sum=;
while(x!=a[x]) {
if (visa[x]) break;
visa[x]=;
sum++;
// cout<<x<<" "<<a[x]<<endl;
x=a[x];
}
//cout<<x<<endl;
if (x==i) {
// cout<<"sum:"<<sum<<endl;
if (sum==) va.push_back();
else va.push_back(sum);
} else {
x=i; int num=;
while(x!=a[x]) {
if (num>=sum) break;
visa[x]=;
num++;
x=a[x];
}
visa[i]=; va.push_back();
}
}
for (int i=; i<m; i++) {
if (visb[i]) continue;
int x=i; int sum=;
while(x!=b[x]) {
if (visb[x]) break;
visb[x]=;
sum++;
x=b[x];
}
if (x==i) {
if (sum==) vb.push_back();
else vb.push_back(sum);
} else {
x=i; int num=;
while(x!=a[x]) {
if (num>=sum) break;
visb[x]=;
num++;
x=b[x];
}
visb[i]=; vb.push_back();
}
}
ll ans=;
for (int i=; i<va.size(); i++) {
ll num=;
for (int j=; j<vb.size(); j++) {
if (va[i]%vb[j]==) num+=vb[j];
}
ans = ans*num%mod;
}
printf("Case #%d: %lld\n", ca++, ans);
}
}
int main() {
//freopen("in.txt","r",stdin);
// freopen("kingdom.in","r",stdin);
//freopen("kingdom.out","w",stdout);
int t=;
// scanf("%d", &t);
while(t--) solve();
}

 

2017年7月25日多校一Function的更多相关文章

  1. 2017年3月25日工作日志:Jquery使用小结[绑定事件判断、select标签、军官证正则]

    jQuery获取DOM绑定事件 在1.8.0版本之前,我们要想获取某个DOM绑定的事件处理程序可以这样: $.data(domObj,'events');//或者$('selector').data( ...

  2. 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS

    一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...

  3. [转载]Ubuntu17.04(Zesty Zapus)路线图发布:2017年4月13日发布

    Canonical今天公布了Ubuntu 17.04(Zesty Zapus)操作系统的发布路线图,该版本于今年10月24日上线启动,toolchain已经上传且首个daily ISO镜像已经生成.面 ...

  4. 2017年1月5日 星期四 --出埃及记 Exodus 21:31

    2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...

  5. 2017年1月4日 星期三 --出埃及记 Exodus 21:30

    2017年1月4日 星期三 --出埃及记 Exodus 21:30 However, if payment is demanded of him, he may redeem his life by ...

  6. 2017年1月3日 星期二 --出埃及记 Exodus 21:29

    2017年1月3日 星期二 --出埃及记 Exodus 21:29 If, however, the bull has had the habit of goring and the owner ha ...

  7. 2017年1月2日 星期一 --出埃及记 Exodus 21:28

    2017年1月2日 星期一 --出埃及记 Exodus 21:28 "If a bull gores a man or a woman to death, the bull must be ...

  8. 2017年1月1日 星期日 --出埃及记 Exodus 21:27

    2017年1月1日 星期日 --出埃及记 Exodus 21:27 And if he knocks out the tooth of a manservant or maidservant, he ...

  9. 2016年12月25日 星期日 --出埃及记 Exodus 21:20

    2016年12月25日 星期日 --出埃及记 Exodus 21:20 "If a man beats his male or female slave with a rod and the ...

随机推荐

  1. css中background-size的属性值

    length 设置背景图像的高度和宽度. 第一个值设置宽度,第二个值设置高度. 如果只设置一个值,则第二个值会被设置为 "auto". percentage 以父元素的百分比来设置 ...

  2. Ambertools15安装(详细)

    这篇博文专门讲述 Ambertools15的安装方法,尽管Ambertools16版本已经正是发行了,但两者在安装方式上没有任何区别.比较偏爱Ambertools15的原因主要还是在容量方面(230M ...

  3. Lattice Constants and Crystal Structures of some Semiconductors

    Lattice Constants and Crystal Structures of some Semiconductors and Other Materials Element or Compo ...

  4. javascript基础:函数参数与闭包问题

    今天在写东西的时候,对函数参数的概念有些模糊,查阅相关资料后,在博客上记点笔记,方便日后复习. 首先,在js中函数参数并没有强语言中那么要求严格,他不介意传递进来多少个参数,也不在乎传进来的参数是什么 ...

  5. 2019年华南理工大学程序设计竞赛(春季赛)-C-六学家的困惑

    题目链接:https://ac.nowcoder.com/acm/contest/625/C 题意:给定两个字符串,每次只能从两个字符串的两端取字符,求依次取字符后所构成的数字最大为多少. 思路:思路 ...

  6. Shc 应用

    1.说明 shc是一个加密shell脚本的工具, 它的作用是把shell脚本转换为一个可执行的二进制文件 2.安装 下载 # mget  http://www.datsi.fi.upm.es/~fro ...

  7. ansible1

    前期工作: 第一步:下载epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 第二步: ...

  8. FZU 2277 Change(dfs序+树状数组)

    Problem Description There is a rooted tree with n nodes, number from 1-n. Root’s number is 1.Each no ...

  9. day 18 类,对象

    类,对象: 类 具有相似功能的一类事物,人类,犬类,猫类等等. 对象: 类的具体表现 面向对象: 1.第一个优点:面向对象是一类相似功能函数的集合体 更清晰化,更规范化 class LoginHand ...

  10. go语言使用go-sciter创建桌面应用(一) 简单的通过html,css写ui

    我们使用go-sciter,就不得不提Sciter,Sciter 是一个嵌入式的 HTML/CSS/脚本引擎,旨在为桌面应用创建一个 UI 框架层. 说简单点就是我们通过它可以像写html,css那样 ...