HDU 1027 Ignatius and the Princess II(全排列)
来源:互联网 发布:儿童 编程培训 编辑:程序博客网 时间:2024/04/30 18:32
题意: 对于给定的 1-n的序列,输出第m个全排列
思路: 注意到m最多只有10000,故最多只需要改变末尾的k个,对末尾的k个进行全排列,然后顺序输出
//#include <iostream>//#include <cstdio>//#include <string>//#include <cstring>//#include <string.h>//#include <cmath>//#include <algorithm>//#include <cctype>//#include <cstdlib>//#include <ctime>//#include <queue>#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int, int> pii;ll dp[50];int main(){ int n, m; while (scanf("%d%d", &n, &m) != EOF) { int all = 1; int p = 1; while (all < m)++p,all *= p; vector<int>v; for (int i = n - p + 1; i <= n; i++)v.push_back(i); do { m--; if (m == 0)break; } while (next_permutation(v.begin(), v.end())); int flag = 0; for (int i = 1; i <= n - p; i++) { if (!flag)flag = 1; else printf(" "); printf("%d", i); } for (int i = 0; i < v.size(); i++) { if (!flag)flag = 1; else printf(" "); printf("%d", v[i]); } printf("\n"); }}
阅读全文
0 0
- HDU 1027 Ignatius and the Princess II(全排列)
- HDU 1027 Ignatius and the Princess II 全排列
- hdu 1027 Ignatius and the Princess II 全排列
- HDU 1027 Ignatius and the Princess II (STL全排列)
- hdu 1027 Ignatius and the Princess II (STL 全排列)
- HDU 1027 Ignatius and the Princess II 全排列
- hdu 1027 Ignatius and the Princess II(STL全排列)
- hdu 1027 Ignatius and the Princess II (全排列)
- 【HDU 1027 Ignatius and the Princess II】+ 全排列 + STL
- HDU-#1027 Ignatius and the Princess II(全排列+STL)
- HDU-1027(Ignatius and the Princess II)(全排列dfs())
- HDU.1027 Ignatius and the Princess II【全排列:关于next_permutation问题】(3.14)
- HDOJ 1027Ignatius and the Princess II(全排列)
- HDOJ 1027-Ignatius and the Princess II【全排列】
- hdoj 1027 Ignatius and the Princess II(全排列变形)
- hdoj 1027 Ignatius and the Princess II 【全排列】【STL】
- hdoj 1027 Ignatius and the Princess II (全排列)
- hdu1027 Ignatius and the Princess II(全排列)
- 数据挖掘与预测分析------数据预处理
- POJ 2312 Battle City 笔记
- 第十七章 再论"没有银弹"
- MapReduce工作原理
- 玩下linux中的的poll函数------可以用任何描述符号fd而不限于网络socket
- HDU 1027 Ignatius and the Princess II(全排列)
- AOJ-problem-09
- Iphone 消息通知(APNS)的3种方式 -- C# 和 nodejs
- kubeadm 安装kubetnetes(flannel)
- html 标签与元素
- UVA 572 POJ 2386 连通块问题
- 多进程共享内存续篇-大锁
- 【修真院“纯洁”系列之十九】驱逐令
- 深入浅出谈接口(interface)和类间继承(extends)