Luogu P3014 [USACO11FEB]牛线Cow Line
题目链接:传送门
康托展开模板
不了解的去找资料自学
很好入手
#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相关推荐
- 洛谷 P3014 [USACO11FEB]牛线Cow Line
P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) ...
- [LUOGU] P2886 [USACO07NOV]牛继电器Cow Relays
https://www.luogu.org/problemnew/show/P2886 给定无向连通图,求经过k条边,s到t的最短路 Floyd形式的矩阵乘法,同样满足结合律,所以可以进行快速幂. 离 ...
- P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(加强版)(贪心+hash哈希)
P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(加强版)(贪心+hash哈希) 洛谷上这道水题丧心病狂地把数据范围加到了500000 普通的做法肯定A不了了, ...
- Cow Line(洛谷-P3014)
题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of thei ...
- 3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 71 Solved: 62 ...
- bzoj 3403: [Usaco2009 Open]Cow Line 直线上的牛
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 206 Solved: 16 ...
- 【BZOJ】3301: [USACO2011 Feb] Cow Line(康托展开)
http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开, ...
- POJ 3617 Best Cow Line(最佳奶牛队伍)
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to t ...
- P2870 [USACO07DEC]Best Cow Line G
P2870 [USACO07DEC]Best Cow Line G 题意: 给你一个字符串,每次从首或尾取一个字符组成字符串,问所有能够组成的字符串中字典序最小的一个. 题解: 现在要组成字典序最小的 ...
最新文章
- PostgreSQL 模式删除背后的代码
- 数据库异地多活解决方案
- spring 源码_spring源码系列(一)——spring循环引用
- python编程培训-马哥教育官网-专业Linux培训班,Python培训机构
- 实用make最佳实践
- 【机器学习】支持向量机面试知识点小结
- Dijkstra 算法——计算有权最短路径(边有权值)
- oel 7.0 安装 mysql 5_在linux上安装PostgreSQL 9.4并启动和关闭数据库
- 你不可不看的 Oracle RAC 日常基本维护命令
- php遍历多维数据库,PHP代码优化之array_column() 使用(解决循环嵌套Sql的问题)
- thinkcmf安装教程与目录结构详解 快速上手版
- 12. 信息系统项目的采购管理
- html怎么设置用户登录界面设计,html怎么做用户登录界面设计步骤,登录界面设计这样做?...
- 车市冷车道 这6款紧凑车苦坐板凳寻伯乐(一)
- 一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念
- 转载:mongo常规操作 大于/小于/不等于……
- size balanced tree (平衡二叉树) ----- 傻X树----陈启峰论文
- 抖音关闭单身开启恋爱模式设置教程分享
- 技术博客哪家强:CSDN、博客园、简书、开源中国OSChina等博客的详细分析比较
- Xeon Phi之MIC编程知识点