HDU 6038 Function 置换群
来源:互联网 发布:上海软件项目经理工资 编辑:程序博客网 时间:2024/06/06 18:56
链接
http://acm.hdu.edu.cn/showproblem.php?pid=6038
题意
给一个排列a,一个排列b,问使得
思路
假设排列a内部只有一个循环节,则:
然后考虑f的取值,在一个循环节内,f的其中一个取值确定了,其它取值也随之确定,因为f可以的取值是
代码
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;#define PB push_back#define MS(x, y) memset(x, y, sizeof(x));typedef long long LL;const int MAXN = 1e5 + 5;const int MOD = 1e9 + 7;int n, m;int a[MAXN], b[MAXN];int len_cnt[MAXN];bool vis[2][MAXN];vector<int> factors[MAXN];int main() { for (int i = 1; i <= 100000 ; ++i) for (int j = i; j <= 100000; j += i) factors[j].PB(i); int kase = 0; while (~scanf("%d%d", &n, &m)) { MS(len_cnt, 0); for (int i = 0; i < n; ++i) { scanf("%d", a + i); vis[0][i] = false; } for (int i = 0; i < m; ++i) { scanf("%d", b + i); vis[1][i] = false; } int num, cnt; for (int i = 0; i < m; ++i) if (!vis[1][i]) { num = i; cnt = 0; while (!vis[1][num]) { ++cnt; vis[1][num] = true; num = b[num]; } ++len_cnt[cnt]; } LL ans = 1, tmp; for (int i = 0; i < n; ++i) if (!vis[0][i]) { num = i; cnt = 0; while (!vis[0][num]) { ++cnt; vis[0][num] = true; num = a[num]; } tmp = 0; for (int factor: factors[cnt]) (tmp += 1LL * factor * len_cnt[factor]) %= MOD; (ans *= tmp) %= MOD; } printf("Case #%d: %I64d\n", ++kase, ans); }}
阅读全文
0 0
- HDU 6038 Function 置换群
- HDU 6038 Function 【置换群】
- hdu 6038 Function【置换群进阶】
- HDU 6038 Function(置换->循环节)
- HDU6038-Function(置换群)
- 2017 多校 Function(置换群
- hdu 4259 置换群
- HDU-置换群
- HDU 5495 置换群
- HDU 5495(置换群)
- hdu 置换群
- 【HDU】1439 Cipher 置换群
- hdu 5495 LCS 置换群
- 【HDU 1439】Cipher(置换群)
- hdu 4529 Double Dealing (置换群)
- HDU 4259 Double Dealing【简单群置换】
- HDU 5495 LCS (置换群)
- HDU 5495 LCS(置换群)
- 产品经理必备神器——Axure软件试用评测
- 深入浅出学Spring Data JPA toPredicate Predicate[] p = new Predicate[list.size()]; query.where(cb.and 201
- MySQL170724
- Greenplum聚合函数的两种实现:HashAggregate与GroupAggregate
- 对List集合嵌套了map集合的排序
- HDU 6038 Function 置换群
- 机器学习之逻辑回归算法
- 禁止Html5在手机上屏幕页面缩放
- 欧拉函数表
- Linux系统服务器上安装MySQL
- 二维数组和vector实现dijkstra
- Vue, App与我(六)
- jQuery插件开发
- Content Provider之间互相通信的源码浅析