杭电1027Ignatius and the Princess II模拟
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1027
题目:
"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> #define PI acos((double)-1)
#define E exp(double(1))
using namespace std;
int j[];
int num[];
void so(int n,int m)
{
int change=,point,all=n;
memset(num,,sizeof(num));
while(m/j[change]==)
change--;
point = n-change;
all=change +;
for(int i =point; i<=n; i++)
num[i]=;
printf("%d",);
for(int i =; i<point; i++)
printf(" %d",i);
while(all--)
{
int t=m/j[change];
for(int i =point,k=; i<=n; i++)
if(num[i])
{
if(k==t)
{
printf(" %d",i);
num[i]=;
break;
}
k++;
}
m%=j[change--];
}
putchar('\n');
}
int main(void)
{
int n, m;
j[]=j[] = ;
for (int i = ; i <= ; i++)
j[i] = j[i - ] * i;
while (scanf("%d%d", &n, &m) == )
{
if(m == )
{
for(int i=; i<=n-; i++)
printf("%d ",i);
printf("%d\n",n);
}
else
so(n,m-);
} return ;
}
杭电1027Ignatius and the Princess II模拟的更多相关文章
- HDU——1027Ignatius and the Princess II(next_permutation函数)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 杭电 1002 A + B Problem II【大数相加】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 解题思路:就是把大的数用数组存放起来,像小学的时候用竖式加法来算两个数相加那样算: 反思:思路很 ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评
最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~
暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...
- 杭电dp题集,附链接还有解题报告!!!!!
Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...
- 杭电ACM题单
杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...
- 2018 Multi-University Training Contest 1 杭电多校第一场
抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001 Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...
随机推荐
- [Tips] Resolve error: server certificate verification failed.
# sympton: piaoger@piaoger-ubuntu:~/w/temp$ git clone https://mygit/solidmcp/solidmcp.gitCloning int ...
- 马尔科夫毯(Markov Blanket)
最优特征子集:选出特征的子集,能够比较准确的代表原来的特征.马尔科夫毯(MB)是贝叶斯网络(BN)的最有特征子集. 推测贝叶斯网络的网络结构是NP问题.贝叶斯网络中一个节点T的马尔科夫毯是其父节点,子 ...
- 【BZOJ】3412: [Usaco2009 Dec]Music Notes乐谱(二分)
http://www.lydsy.com/JudgeOnline/problem.php?id=3412 维护前缀和,然后直接二分即可... #include <cstdio> #incl ...
- tplink 703刷固件
1.软件下载: ImageBuilder链接 如果是全新刷机的话,使用:http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/open ...
- ShadowCaster 代码
Pass { Name "ShadowCaster" Tags{"LightMode" = "ShadowCaster"} CGPROGRA ...
- js的实例方法和静态方法分析
var Person=function(){}; Person.say=function(){ console.log('I am a Person,I can say.') }; Person.pr ...
- cannot be cast to javax.servletFilter
java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast ...
- vue+node+mongoDB 火车票H5(一)---准备工作,基本配置
前端菜鸟一枚,由于公司项目用到了vue,我虽然参与了,但是很多环境配置和流程还不是特别清楚,就想自己个人业余做个webapp看看, 对于完全新手而言,很多坑会纠结很久,所以想借此机会自己做的同时记录各 ...
- idle命令行按ALT+P重复调出上个语句
idle命令行按ALT+P重复调出上个语句
- Java应用多机器部署定时任务解决方案
Java多机部署下定时任务的处理方案. 本文转自:http://www.cnblogs.com/xunianchong/p/6958548.html 需求: 有两台服务器同时部署了同一套代码, 代码中 ...