D. Artsem and Saunders
一个变换题
给定f(x),[1,n]->[1,n]
构造g(x),h(x)满足:
g(h(x))=x [1,n]->[1,m]
h(g(x))=f(x) [1,m]->[1,n]
根据已知条件,等效替换变形:
h(g(h(x)))=f(h(x))
=>h(x)=f(h(x))
=>h(g(x))=f(h(g(x)))
=>f(x)=f(f(x)) //是不是有点类似并查集找爸爸
另一方面:
g(h(g(x)))=g(x)
=>g(x)=g(f(x))
这里我们又可以发现f,g,h三个函数的值域其实都是[1,m],等价于将n个元素分为m类
那么题目意思是不是可以转化成:
f(i):找i这个元素的爸爸元素是谁
g(i):找元素i属于哪一类
h(i):找第i类的爸爸元素是谁
这不就是很经典的(排名<<=>>权值)互换函数么
int n, m;
int f[N], g[N], h[N];
int vis[N]; int main()
{
#ifndef ONLINE_JUDGE
file("test");
#endif
sdf(n);
For(i, 1, n) sdf(f[i]);
For(i, 1, n)
{
if (f[f[i]] != f[i])
{
cout << -1;
return 0;
}
if (!vis[f[i]])
h[++m] = f[i], g[f[i]] = m,vis[f[i]]=1;
g[i] = g[f[i]];
}
cout << m << endl;
For(i, 1, n) cout << g[i] << " ";
cout << endl;
For(i, 1, m) cout << h[i] << " ";
D. Artsem and Saunders的更多相关文章
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders 数学 构造
D. Artsem and Saunders 题目连接: http://codeforces.com/contest/765/problem/D Description Artsem has a fr ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders
地址:http://codeforces.com/contest/765/problem/D 题目: D. Artsem and Saunders time limit per test 2 seco ...
- Codeforces Round #397 Div. 2 D. Artsem and Saunders
http://codeforces.com/problemset/problem/765/D 题意: 有一个函数f,f: [n] → [n] 的意思就是定义域为[1,n],每个x值对应于[1,n]内的 ...
- 【构造】Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders
根据那两个式子 g(h(x))=x h(g(x))=f(x) 可以推出来两个新的式子 g(f(x))=g(x) h(x)=f(h(x)) 于是,我们先找到f(x)的所有不动点,有几个不动点,m就是多少 ...
- D. Artsem and Saunders 数学题
http://codeforces.com/contest/765/problem/D 这题的化简,不能乱带入,因为复合函数的带入,往往要严格根据他们的定义域的 题目要求出下面两个函数 g[h(x)] ...
- 【codeforces 765D】Artsem and Saunders
[题目链接]:http://codeforces.com/contest/765/problem/D [题意] 给你一个函数f(x); 要让你求2个函数g[x]和h[x],使得g[h[x]] = x对 ...
- Codeforces_765_D. Artsem and Saunders_(数学)
D. Artsem and Saunders time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
运气好,分到的房里我最先开始Hack C题,Hack了12个,听说F题沙雕莫队但我不会,最后剩不到15分钟想出E题做法打了一波结果挂了,最后虽然上分了但总有点不甘心. 最后A掉ABCD Hack+12 ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造
A. Neverending competitions time limit per test 2 seconds memory limit per test 512 megabytes input ...
随机推荐
- 【代码笔记】Web-JavaScript-JavaScript正则表达式
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- loadrunner 脚本录制-Protocol Advisor协议分析器的使用
脚本录制-Protocol Advisor协议分析器的使用 by:授客 QQ:1033553122 1.启动Protocol Advisor File > Protocol Advisor &g ...
- Python高级特性:列表生成式
列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式. 最常见的例子: 生成list [, , , , , , , , , ]可以用li ...
- exports与module.exports的区别,export与export.defult区别
在JS模块化编程中,之前使用的是require.js或者sea.js.随着前端工程化工具webpack的推出,使得前端js可以使用CommonJS模块标准或者使用ES6 moduel特性. 在Comm ...
- Git多人协作常用命令
Git多人协作工作模式: 首先,可以试图用git push origin branch-name推送自己的修改. 如果推送失败,则因为远程分支比你的本地更新早,需要先用git pull试图合并. 如果 ...
- 2016-04-25-信息系统实践手记6-JS调用Flex的性能问题一例
layout: post title: 2016-04-25-信息系统实践手记6-JS调用Flex的性能问题一例 key: 20160425 tags: GIS JS FLEX 技术选型 性能 API ...
- mssql sqlserver SQL 位运算举例权限应用
摘要: 下文通过举例的方式讲述sqlserver中位运算的相关知识,如下所示: 实验环境:sqlserver 2008 R2 在sqlserver的权限设置,我们通常使用1.2.4.8.16.32.6 ...
- web前端(13)—— 了解JavaScript,JavaScript的引入方式
从本篇博文开始,将进入web前端方便最关键最重要的部分——javascript,学到后面你就知道它真的太重要了 什么是JavaScript JavaScript一种直译式的脚本语言,是一种动态类型.弱 ...
- Python语法的转义字符
Python语法的转义字符 转义字符 说 明 \ 续行符 \n 换行符 \0 空 \t 水平制表符,用于横向跳到下一制表位 \'' 双引号 \' 单引号 \\ 一个反斜杠 \f 换页 \0dd 八进 ...
- c/c++ 模板与STL小例子系列<一 >自建Array数组
c/c++ 模板与STL小例子系列 自建Array数组 自建的Array数组,提供如下对外接口 方法 功能描述 Array() 无参数构造方法,构造元素个数为模板参数个的数组 Array(int le ...