2017年7月25日多校一Function
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的更多相关文章
- 2017年3月25日工作日志:Jquery使用小结[绑定事件判断、select标签、军官证正则]
jQuery获取DOM绑定事件 在1.8.0版本之前,我们要想获取某个DOM绑定的事件处理程序可以这样: $.data(domObj,'events');//或者$('selector').data( ...
- 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS
一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...
- [转载]Ubuntu17.04(Zesty Zapus)路线图发布:2017年4月13日发布
Canonical今天公布了Ubuntu 17.04(Zesty Zapus)操作系统的发布路线图,该版本于今年10月24日上线启动,toolchain已经上传且首个daily ISO镜像已经生成.面 ...
- 2017年1月5日 星期四 --出埃及记 Exodus 21:31
2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- c#实现动态加载Dll(转)
c#实现动态加载Dll 分类: .net2009-12-28 13:54 3652人阅读 评论(1) 收藏 举报 dllc#assemblynullexceptionclass 原理如下: 1.利用反 ...
- Spyder启动黑屏,终端显示QOpenGLShaderProgram::uniformLocation(qt_Matrix): shader program is not linked QOpenG
cd /etc/ld.so.conf.d目录中有 i386-linux-gnu_GL.conf and x86_64-linux-gnu_GL.conf等文件cat x86_64-linux-gnu_ ...
- Gym - 101911C Bacteria (规律题)
传送门:点我 Time limit2000 ms Memory limit262144 kB Recently Monocarp has created his own mini-laboratory ...
- TOJ 4383 n % ( pow( p , 2) ) ===0
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4383 描述 There is a ...
- CodeForces - 873B Balanced Substring(思维)
inputstandard input outputstandard output You are given a string s consisting only of characters 0 a ...
- stark组件之搜索【模仿Django的admin】
一.先看下django的admin是如何做搜索功能的 配置一个search_fields的列表就可以实现搜索的功能 class testbook(admin.ModelAdmin): # 第一步,定义 ...
- ubuntu下nginx的常用操作
1.安装不多说了,我是使用apt-get进行安装的,直接键入 apt-get install nginx 2.启动nginx. 首先找到nginx的主运行程序(相当于windows下的nginx.ex ...
- 设置导航栏和TabBar标题的文字格式
//TabBar样式 [navi.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSiz ...
- AngularJS——第8章 服务
第8章 服务 服务是一个对象或函数,对外提供特定的功能. 8.1 内建服务 1. $location是对原生Javascript中location对象属性和方法的封装. // $location内置服 ...
- bug定位
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...