vijosP1115 火星人
vijosP1115 火星人
【思路】
排列组合。
题目要求为求第下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 火星人的更多相关文章
- 1014: [JSOI2008]火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...
- [BZOJ1014][JSOI2008]火星人prefix
[BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...
- BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6243 Solved: 2007[Submit] ...
- BZOJ 1014 【JSOI2008】 火星人prefix
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...
- 【BZOJ-1014】火星人prefix Splay + 二分 + Hash
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 5852 Solved: 1871[Submit] ...
- 【bzoj1014】[JSOI2008]火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6031 Solved: 1917[Submit] ...
- BZOJ 1014: [JSOI2008]火星人prefix Splay+二分
1014: [JSOI2008]火星人prefix 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1014 Description 火星人 ...
- 1014: [JSOI2008]火星人prefix - BZOJ
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...
- JSOI2008 火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2918 Solved: 866[Submit][ ...
随机推荐
- apache开启gzip的方法
在Apache中开启gzip压缩方法为: 1. 在httpd.conf 或者博客根目录的.htaccess文件中加入如下规则(Apache服务器需要支持 mod_deflate) 本文出处参考:htt ...
- css text-overflow溢出文本显示省略号
<div style="width: 100px; overflow: hidden; text-overflow:ellipsis"> <nobr>当对象 ...
- apache设置映射文件夹的配置方法
在apache的配置文件中加入以下配置 Alias /uploadImage F:/upload <Directory F:/upload/UploadFiles> Option ...
- vb delphi7、2010 csharp vb.net空白测试程序
工作中难免在网上看到一段不错的代码,希望能够拿来测试一次,为了避免每次测试都要新建一个空白测试程序,索性预先建立好,要用的时候复制一遍,然后打开直接粘贴需要测试的代码进行测试.
- Nginx+uWSGI+bottle 在Linux上部署
在/data/lujianxing/bottle 文件夹中创建三个文件: bottle.py bottle的源文件 a.py from bottle import Bottle, run mybott ...
- thinkphp 框架的学习(1) 扩展配置文件
在config.php里面写入 1:'LOAD_EXT_CONFIG' => array('SETTINGS' => 'settings'); 系统会判断是否有参数:LOAD_EXT_CO ...
- 一步步学习ASP.NET MVC3 (15)——过滤器
请注明转载地址:http://www.cnblogs.com/arhat 今天老魏和大家一起讨论一下ASP.NET MVC中非常重要的一个知识:"过滤器".那么这个"过滤 ...
- js函数语法
<script type="text/javascript"> //1 普通方法 /* * function 方法名(参数){ * 方法体 * ...
- javascript中部分不能使用call apply调用来重写的构造函数
This tests if TypeError is thrown or not when we call a constructor as a normal function. On ...
- javascript移动设备触屏事件
ontouchstartontouchmoveontouchendontouchcancel 目前移动端浏览器均支持这4个触摸事件: /** * onTouchEvent */ var div = d ...