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. js中window.onload 与 jquery中$(document.ready()) 測试

    js中window.onload 与 jquery中$(document.ready())差别,验证代码例如以下(调换js代码和Jquer代码书写顺序測试.执行结果一样.因此与代码书写位置没关系): ...

  2. mtk刷机错误汇总

    MTK常见错误解读与解决方法: 1.刷机过了红条,到了紫色条卡住.(错误代码4008) 解决方法:这种情况出现的话,大家可以把电池拿下来,然后重新安装上,进入REC后选择关机.然后重新刷. 2.驱动安 ...

  3. 【网站支付PHP篇】thinkPHP集成支付宝支付(担保交易)

    目录 系列说明 开发环境 部署支付宝 支付请求 支付宝返回处理 系列说明 最近在帮朋友的系统安装支付模块(兑换网站积分),现在总结一些开发心得,希望对大家有用.这个系列会讲以下第三方支付平台的集成: ...

  4. 【翻译自mos文章】在12c中Create or Truncate Table时非常慢,等待事件为 DFS Lock Handle wait

    来源于: Create or Truncate Table Slow in 12c While Waiting for DFS Lock Handle wait (文档 ID 2085308.1) A ...

  5. [学习笔记]overthewire bandit 通关秘籍

    1.第一关 使用putty等工具连入linux即可,注意port等设置. ls 列目录内文件: cat readme,显示文件内容,即可看到密码. 2.第二关 如何查看文件名为-的文件? cat ./ ...

  6. 2016/3/31 ①全选时 下面选项全选中 ② 下面不选中时 全选取消 ③在“” 中 转义字符的使用\ onclick=\"Checkpa(this,'flall')\"; ④区别于分别实现 重点在于两种情况合并实现

    testxuanbuxuan.php <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  7. 更改Mysql登录密码

    版本号49之前的跨域设置 在Windows命令行下修改mysql数据库密码步骤如下: 1.通过dos命令进入mysql的bin目录: 2.输入“mysql -uroot -p”,回车进入mysql命令 ...

  8. MVC优缺点

    1.通过把项目分成model view和controller,使得复杂项目更加容易维护. 2.没有使用view state和服务器表单控件,可以更方便的控制应用程序的行为 3.应用程序通过contro ...

  9. vue学习1

    1.<div id="app">{{message}}<input v-model="message"></div>new ...

  10. linux网络socket 接口转

    linux网络socket 接口 1.socket函数:一个进程必须做的第一件事就是调用socket函数获得一个文件描述符. ------------------------------------- ...