vijosP1115 火星人

链接:https://vijos.org/p/1115

【思路】

排列组合。

题目要求为求第下m个排列。

这里有两种方法,首选的是调用algorithm中的next_permutation函数,其次就是手写生成函数。

【代码1】53ms

 #include<iostream>
#include<algorithm>
using namespace std;
const int maxn = +;
int p[maxn];
int n,m; int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<n;i++) cin>>p[i]; while(m--) next_permutation(p,p+n); for(int i=;i<n;i++) cout<<p[i]<<" "; return ;
}

【代码2】106ms

 #include<iostream>
#include<algorithm>
using namespace std;
const int maxn = +;
int p[maxn];
int n,m; bool get_permutation() {
int i=n-;
while(i> && p[i-] >= p[i]) i--;
if(i==) return false;
int mp=i;
for(int j=i+;j<n;j++) {
if(p[j]<=p[i-]) continue;
if(p[j]<p[mp]) mp=j;
}
swap(p[mp],p[i-]);
sort(p+i,p+n);
return true;
} int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<n;i++) cin>>p[i]; while(m--) get_permutation(); for(int i=;i<n;i++) cout<<p[i]<<" "; return ;
}

vijosP1115 火星人的更多相关文章

  1. 1014: [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...

  2. [BZOJ1014][JSOI2008]火星人prefix

    [BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...

  3. BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6243  Solved: 2007[Submit] ...

  4. BZOJ 1014 【JSOI2008】 火星人prefix

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  5. 【BZOJ-1014】火星人prefix Splay + 二分 + Hash

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5852  Solved: 1871[Submit] ...

  6. 【bzoj1014】[JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6031  Solved: 1917[Submit] ...

  7. BZOJ 1014: [JSOI2008]火星人prefix Splay+二分

    1014: [JSOI2008]火星人prefix 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1014 Description 火星人 ...

  8. 1014: [JSOI2008]火星人prefix - BZOJ

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  9. JSOI2008 火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2918  Solved: 866[Submit][ ...

随机推荐

  1. 最近在无线USB网卡投入比较大

    第一次(40): 乐光N18网卡 17 5米USB延长线 10 DVD2 3 运费10 第二次(30): 8187L主板13 5DB/6DB全向天线 5 外壳FREE 运费12 第三次(20): 8D ...

  2. Centos 6.2上安装使用 Informix11.70 数据库

    环境要求:操作系统: Centos 6.2 32位数据库软件: iif.11.70.UC7IE.Linux-RHEL5.tar(在IBM网站上注册个帐号就可以下载,包括windows,Linux,Un ...

  3. 7.MVC框架开发(创建层级项目)

    在一个项目比较大的时候,就会有多个层级项目 1)在项目中选定项目右建新建区域(新的层级项目),项目->右键->添加->区域,构成了一套独立的MVC的目录,这个目录包括Views,Co ...

  4. 【单片机通信协议】CAN总线基础知识

    CAN总线基础知识(一) 1.1 CAN总线是什么? CAN(Controller Area Network)是ISO国际标准化的串行通信协议.广泛应用于汽车.船舶等.具有已经被大家认可的高性能和可靠 ...

  5. C# - 参数数组Params

    参数数组可以使用个数不定的参数调用函数,此时用params关键字定义它们. 限制:必须是函数定义中的最后一个参数:必须是同一类型的. 优点:不用在调用代码中传入数组,指定参数个数不受限制,可以不指定该 ...

  6. ios coredata 老代码备用参考

    iPhone OS在2009年6月份推出3.0版本SDK,其中一个特性是引入了Mac SDK中的core data.是一种ORM(Object Relationships Mapping)解决方案,类 ...

  7. HTTP错误 404.17

    HTTP错误 404.17 - Not Found" IIS 7.5 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理   出现这种情况的原因通常是因为先安装了Framework,后 ...

  8. hadoop 2.2.0 编译报错: [ERROR] class file for org.mortbay.component.AbstractLifeCycle not found

    [ERROR]  class file for org.mortbay.component.AbstractLifeCycle not found 错误堆栈如下: [ERROR] COMPILATIO ...

  9. A Neural Network in 11 lines of Python

    A Neural Network in 11 lines of Python A bare bones neural network implementation to describe the in ...

  10. Unity3D连接真机调试教程,可抓断点

    源地址:http://www.unity蛮牛.com/thread-19586-1-1.html <ignore_js_op> 未标题-1.jpg (52.33 KB, 下载次数: 0) ...