HDU1027Ignatius and the Princess II(排序)
来源:互联网 发布:汽配数据服务商 编辑:程序博客网 时间:2024/05/21 11:04
题目大意:给出1,2……n的序列,输出第m小的序列;1,2,3,……n是最小的序列,1,2,3……n,n-1是第2小的序列;给出你两个数n,m,(n表示有n个数,m表示第m小的序列),输出第m小的序列:
题目解析:此题和HDU1716题差不多,只需修改一些输出内容;不过我想了好久才想到,呵呵……
错误分析:此题要注意找到满足的答案,就不要再让它递归了,要不然就TEL!!!
#include<cstdio>#include<cstring>using namespace std;#define M 1005int ret[M],use[M],a[M];//ret[]记录每个位置要填的数;use标记是否使用过,int n,m;int flag;//标记是否是m小的序列void mth_small(int l ){ int i; if(flag==m)return;//注意找到满足的答案,就不要再让它递归了,要不然就TEL if(l==n&&m==++flag) { for( i=0;i<n;i++) { printf("%d",ret[i]); if(i<n-1) printf(" "); } printf("\n"); return;//注意找到后就不要往下运行了 } for(i=0;i<n;i++) { if(!use[i]) { use[i]=1;ret[l]=a[i]; mth_small(l+1); use[i]=0; } }}int init(){ int i,j; int x,k=0; memset(use,0,sizeof(use)); if(scanf("%d%d",&n,&m)==EOF)return 0; for( i=0;i<n;i++) a[i]=i+1; flag=0; return 1;}int main(){ while(init()) mth_small(0); return 0;}
- HDU1027Ignatius and the Princess II(排序)
- hdu1027Ignatius and the Princess II
- hdu1027Ignatius and the Princess II <vector>
- 搜索专题: HDU1027Ignatius and the Princess II
- 【全排列】HDU1027Ignatius and the Princess II/HDU1716排列2
- HDU1027(Ignatius and the Princess II)
- Ignatius and the Princess II( next_permutation() )
- Ignatius and the Princess II(bfs)
- Ignatius and the Princess II
- Ignatius and the Princess II
- Ignatius and the Princess II
- Ignatius and the Princess II
- Ignatius and the Princess II
- HDOJ 题目1027 Ignatius and the Princess II(STL)
- Ignatius and the Princess II(C++ stl)
- hdu1027 Ignatius and the Princess II(全排列)
- HDU1027 - Ignatius and the Princess II (深搜)
- hdoj Ignatius and the Princess II (全排列)
- 实用技巧:Google 搜索打不开的解决方法【图文教程】
- 解决Android网络编程中的connection refused
- 第五章 Web服务器
- Java 数据类型转换【学习备份】
- 服务器端Server-U忘记密码的解决办法
- HDU1027Ignatius and the Princess II(排序)
- MySQL不需循环update多条记录
- (**)hibernate中基于主键和基于外键的one-to-one
- 两日期之间的天数
- 命令行下执行SQL sever 语句操作数据库的方法
- 整理CSS中遇到的一些常见问题
- as3.0实现小涂鸦效果
- ASP.NET 的授权和认证
- CF305C--------数学题