http://codeforces.com/contest/765/problem/D

这题的化简,不能乱带入,因为复合函数的带入,往往要严格根据他们的定义域的

题目要求出下面两个函数

g[h(x)] = x。这个函数的值域[1, m],定义域[1, n]

h[g(x)] = f(x)。这个函数的值域[1, n],定义域[1, m]

设任意一个数t、和A。使得g[t] = A,也就是有h[A] = t了。

h[A] = h[g(t)] = f(t),那么就是f(t) = t的时候,会使得g[t] = A,h[A] = t

A的值从1...n模拟过去。

这样就能得到g[]和h[]

当然,g[]有些是0,也就是空的,这个时候去找h[]任何一个满足g[pos] = x。就行。

其他的就是细节了。

 8
1 2 3 2 1 2 3 2
 
 5
1 2 2 1 1 
 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e6 + ;
int f[maxn];
int g[maxn];
int h[maxn];
int ans[maxn];
int mph[maxn];
void work() {
int n;
cin >> n;
for (int i = ; i <= n; ++i) cin >> f[i];
int m = ;
for (int i = ; i <= n; ++i) {
if (f[i] == i) {
g[i] = ++m;
h[m] = i;
mph[i] = m;
}
}
if (m == ) {
cout << "-1" << endl;
return;
}
// for (int i = 1; i <= n; ++i) {
// if (g[i] == 0) g[i] = 1;
// }
for (int i = ; i <= n; ++i) {
if (g[i] != && h[g[i]] != f[i]) {
cout << - << endl;
return;
}
if (g[i] == ) {
if (!mph[f[i]]) {
cout << - << endl;
return;
}
g[i] = mph[f[i]];
}
if (i <= m && g[h[i]] != i && g[h[i]] != ) {
cout << - << endl;
return;
}
if (i <= m && g[h[i]] == ) {
g[h[i]] = i;
i--;
}
// i--;
}
cout << m << endl;
for (int i = ; i <= n; ++i) {
cout << g[i] << " ";
}
cout << endl;
for (int i = ; i <= m; ++i) {
cout << h[i] << " ";
}
cout << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

D. Artsem and Saunders 数学题的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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] 根 ...

  4. 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]内的 ...

  5. 【构造】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就是多少 ...

  6. 【codeforces 765D】Artsem and Saunders

    [题目链接]:http://codeforces.com/contest/765/problem/D [题意] 给你一个函数f(x); 要让你求2个函数g[x]和h[x],使得g[h[x]] = x对 ...

  7. Codeforces_765_D. Artsem and Saunders_(数学)

    D. Artsem and Saunders time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. COCOS2DX学习之Box2d物理引擎使用之------动态物体的创建

    1.创建一个物理世界 首先要引入一个头文件#include "Box2D\Box2D.h" 之后利用b2word创建一个对象,而且指定这个物理世界中的加速度方向. word = n ...

  2. Python第五讲

    一.冒泡算法 1.将两个变量的值互换 a1 = 123 a2 = 456 #要想将a1与a2的值进行位置互换需要借助一个中间变量(temp) temp = a1#将a1的值赋值给temp(temp=1 ...

  3. 点滴记录——Ubuntu 14.04中Solr与Tomcat整合安装

    转载请说明出处:http://blog.csdn.net/cywosp/article/details/38965981 1. 安装jdk,tomcat     sudo apt-get instal ...

  4. Android 使用图片异步载入框架Universal Image Loader的问题

    使用的Jar包 问题:        optionsm = new DisplayImageOptions.Builder()         .displayer(new RoundedBitmap ...

  5. jquery源码学习笔记三:jQuery工厂剖析

    jquery源码学习笔记二:jQuery工厂 jquery源码学习笔记一:总体结构 上两篇说过,query的核心是一个jQuery工厂.其代码如下 function( window, noGlobal ...

  6. (八)Java 修饰符

    Java 修饰符 Java语言提供了很多修饰符,主要分为以下两类: 访问修饰符 非访问修饰符 修饰符用来定义类.方法或者变量,通常放在语句的最前端.我们通过下面的例子来说明: public class ...

  7. PyTorch 60 分钟入门教程

    PyTorch 60 分钟入门教程:PyTorch 深度学习官方入门中文教程 http://pytorchchina.com/2018/06/25/what-is-pytorch/ PyTorch 6 ...

  8. mongo14-----group,aggregate,mapReduce

    group,aggregate,mapReduce 分组统计: group() 简单聚合: aggregate() 强大统计: mapReduce() db.collection.group(docu ...

  9. Eclipse 插件管理

    查看已安装的插件: [help]⇒ [About Eclipse]⇒ [Installed Softwares] 1. 常用插件 maven:安装步骤如下: [help]⇒ [Install new ...

  10. settings.xml 文件配置

    Maven 远程中央仓库:repo1.maven.org 通过 ping repo1.maven.org 查看该网络是否可以连接访问: 1. 设置代理 Plugin org.apache.maven. ...