题目链接:传送门

康托展开模板
不了解的去找资料自学
很好入手

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define A 1000010
#define B 2010using namespace std;
typedef long long ll;
#define int ll
ll cantor(int *a, int n) {ll ans = 0;for (int i = 1; i <= n; i++) {ll x = 0; int c = 1; ll m = 1;for (int j = i + 1; j <= n; j++) {if (a[j] < a[i]) x++;m *= c; c++;}ans += x * m;}return ans;
}
ll fac[21];
void decantor(int x, int n) {vector<int> v, a;for (int i = 1; i <= n; i++) v.push_back(i);for (int i = n; i >= 1; i--) {int r = x % fac[i - 1];int t = x / fac[i - 1];x = r;sort(v.begin(), v.end());a.push_back(v[t]);v.erase(v.begin() + t);}for (auto it = a.begin(); it != a.end(); it++) cout << *it << " "; puts("");
}
int n, q, x, d[21];signed main(signed argc, char const *argv[]) {cin >> n >> q; fac[0] = 1;for (ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i;while (q--) {char c; cin >> c;if (c == 'P') {cin >> x;decantor(x - 1, n);}else {for (int i = 1; i <= n; i++) cin >> d[i];cout << cantor(d, n) + 1 << endl;}}
}

Luogu P3014 [USACO11FEB]牛线Cow Line相关推荐

  1. 洛谷 P3014 [USACO11FEB]牛线Cow Line

    P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) ...

  2. [LUOGU] P2886 [USACO07NOV]牛继电器Cow Relays

    https://www.luogu.org/problemnew/show/P2886 给定无向连通图,求经过k条边,s到t的最短路 Floyd形式的矩阵乘法,同样满足结合律,所以可以进行快速幂. 离 ...

  3. P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(加强版)(贪心+hash哈希)

    P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(加强版)(贪心+hash哈希) 洛谷上这道水题丧心病狂地把数据范围加到了500000 普通的做法肯定A不了了, ...

  4. Cow Line(洛谷-P3014)

    题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of thei ...

  5. 3403: [Usaco2009 Open]Cow Line 直线上的牛

    3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 71  Solved: 62 ...

  6. bzoj 3403: [Usaco2009 Open]Cow Line 直线上的牛

    3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 206  Solved: 16 ...

  7. 【BZOJ】3301: [USACO2011 Feb] Cow Line(康托展开)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开, ...

  8. POJ 3617 Best Cow Line(最佳奶牛队伍)

    POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...

  9. P2870 [USACO07DEC]Best Cow Line G

    P2870 [USACO07DEC]Best Cow Line G 题意: 给你一个字符串,每次从首或尾取一个字符组成字符串,问所有能够组成的字符串中字典序最小的一个. 题解: 现在要组成字典序最小的 ...

最新文章

  1. PostgreSQL 模式删除背后的代码
  2. 数据库异地多活解决方案
  3. spring 源码_spring源码系列(一)——spring循环引用
  4. python编程培训-马哥教育官网-专业Linux培训班,Python培训机构
  5. 实用make最佳实践
  6. 【机器学习】支持向量机面试知识点小结
  7. Dijkstra 算法——计算有权最短路径(边有权值)
  8. oel 7.0 安装 mysql 5_在linux上安装PostgreSQL 9.4并启动和关闭数据库
  9. 你不可不看的 Oracle RAC 日常基本维护命令
  10. php遍历多维数据库,PHP代码优化之array_column() 使用(解决循环嵌套Sql的问题)
  11. thinkcmf安装教程与目录结构详解 快速上手版
  12. 12. 信息系统项目的采购管理
  13. html怎么设置用户登录界面设计,html怎么做用户登录界面设计步骤,登录界面设计这样做?...
  14. 车市冷车道 这6款紧凑车苦坐板凳寻伯乐(一)
  15. 一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念
  16. 转载:mongo常规操作 大于/小于/不等于……
  17. size balanced tree (平衡二叉树) ----- 傻X树----陈启峰论文
  18. 抖音关闭单身开启恋爱模式设置教程分享
  19. 技术博客哪家强:CSDN、博客园、简书、开源中国OSChina等博客的详细分析比较
  20. Xeon Phi之MIC编程知识点

热门文章

  1. 简单贪心问题-圣诞老人的礼物
  2. 【面经】度小满 测试研发工程师 一面二面面经
  3. CNN(卷积神经网络)在视频动作分类中的应用
  4. FVCOM - SMS - 画网格
  5. 气化及燃烧相关知识点
  6. 内网渗透神器CobaltStrike之DNS Beacon(四)
  7. 关于WinGate代理服务器的概述
  8. 2019年3月CCF CSP 认证题解第一题
  9. 文旅景区夜游该如何设计项目
  10. 企业建站为何会出问题?责任在谁?