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. 2 Angular 2 的核心概念

    一.组件(Components): 组件是构成 Angular 应用的基础和核心,它是一个模板的控制类,用于处理应用和逻辑页面的视图部分.组件知道如何渲染自己及配置依赖注入,并通过一些由属性和方法组成 ...

  2. 嵌入式开发之davinci--- 8148 小站信息

    http://zhan.renren.com/tag?value=dm8148#!//more/3602888498051423017 http://zhan.renren.com/dm8148evm ...

  3. 【iOS系列】-iOS的多线程解析

    [iOS系列]-iOS的多线程解析 iOS的多线程实现技术: 1:GCD -- Grand Central Dispatch 是基于C语言的底层API 用Block定义任务,使用起来非常灵活便捷 提供 ...

  4. Nyquist–Shannon sampling theorem 采样定理

    Nyquist–Shannon sampling theorem - Wikipedia https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_s ...

  5. CASE UPDATE

    https://leetcode-cn.com/problems/swap-salary/description/ Given a table salary, such as the one belo ...

  6. js权威指南

    有很多js的细节基础不太了解,希望能通过阅读这本书查漏补缺!长期更新!

  7. YTU 1098: The 3n + 1 problem

    1098: The 3n + 1 problem 时间限制: 1 Sec  内存限制: 64 MB 提交: 368  解决: 148 题目描述 Consider the following algor ...

  8. SELinux 初探

    SELinux:Security Enhanced Linux.SELinux 是 NSA(美国国家安全局)开发设计,整合到 Linux 内核中的一个模块. 0. 基本概念 DAC(Discretio ...

  9. ab压力测试-突破最大线程数

    ab压力测试中,发现你一次最多只能启动1024个线程 默认情况下,一个线程的栈要预留1M的内存空间 而一个进程中可用的内存空间只有2G,所以理论上一个进程中最多可以开2048个线程 但是内存当然不可能 ...

  10. Python实现跨文件全局变量的方法

    Python 中 global 关键字可以定义一个变量为全局变量,但是这个仅限于在一个模块(py文件)中调用全局变量,在另外一个py文件 再次使用 global x 也是无法访问到的,因为在这个py模 ...