链接:传送门

题意:

思路:next_permutation(),水,但是要注意一点的是如果是最后一个排列next_permutation会返回第一个排列并结束,所以如果到了最后一个排列还不是第k个就处理一下即可

/*************************************************************************
> File Name: 31.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年04月19日 星期三 22时15分06秒
************************************************************************/ #include<cstdio>
#include<algorithm>
using namespace std; int t,n,k;
int s[1034];
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",s+i);
int cnt = 0 , i;
do{
cnt++;
for(i=0;i<n;i++)
if(s[i]!=n-i) break;
if(i==n){
cnt++;
for(int i=0;i<n;i++) s[i]=i+1;
}
if(cnt == k+1) break;
}while(next_permutation(s,s+n));
for(int i=0;i<n;i++) printf("%d%c",s[i],i==n-1?'\n':' ');
}
return 0;
}

POJ 1883 排序 ( 水 + next_permutation )的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. POJ.1003 Hangover ( 水 )

    POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...

  3. POJ.1552 Doubles(水)

    POJ.1552 Doubles(水) 题意分析 暴力 代码总览 #include <cstdio> #include <stdio.h> #define nmax 100 u ...

  4. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

  5. POJ 2388(排序)

    http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...

  6. PAT甲题题解-1012. The Best Rank (25)-排序水题

    排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...

  7. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...

  8. POJ 1833 排序

    http://poj.org/problem?id=1833 题意: 给出一个排序,求出它之后的第k个排序. 思路: 排序原理: 1.如果全部为逆序时,说明已经全部排完了,此时回到1~n的排序. 2. ...

  9. POJ 3050 Hopscotch 水~

    http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...

随机推荐

  1. 使用requests爬取小说

    实现: import requests import re import time def get_chapter(aim_url): ''' 获取小说章节名称和对应的url地址 :param aim ...

  2. C调用java方法签名

    1.AS2.0 D:\androidMyWork\SmartCam\app\build\intermediates\classes\debug>javap -s com.admin.smartc ...

  3. Matlab中的函数句柄@

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50699990 @是Matlab中的句柄 ...

  4. ssm整合shiro—实现认证和授权

    1.简述 1.1    Apache Shiro是Java的一个安全框架.是一个相对简单的框架,主要功能有认证.授权.加密.会话管理.与Web集成.缓存等. 1.2   Shiro不会去维护用户.维护 ...

  5. POJ 1284

    想了很久,只想到枚举的方法,估计会超时吧. 原来有这样一条性质:p为素数,则p有phi(p-1)个原根 Orz... #include <iostream> #include <cs ...

  6. jQuery Mobile页面跳转切换的几种方式

    jQuery Mobile在移动开发中越来越受到欢迎. 而他的各个版本号也在持续不断的更新中.相同的我也非常喜欢它,它加快了我们开发HTML5的速度. 同一时候又具备jQuery一样的操作方法. 学起 ...

  7. Java Secret: Using an enum to build a State machine(Java秘术:用枚举构建一个状态机)

    近期在读Hadoop#Yarn部分的源代码.读到状态机那一部分的时候,感到enmu的使用方法实在是太灵活了,在给并发编程网翻译一篇文章的时候,正好碰到一篇这种文章.就赶紧翻译下来,涨涨姿势. 原文链接 ...

  8. OpenST Basic tool library

    /***************************************************************************** * OpenST Basic tool l ...

  9. Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires

    Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires ...

  10. 【MySQL】MySQL删除匿名用户,保证登录安全

    博客地址已迁往 www.virtclouds.com 原文地址 http://www.virtclouds.com/538.html 很多MySQL程序都会带有匿名登录的功能. 在刚刚安装完MySQL ...