HDU1027(STL)

题目大意:全排列

有关全排列:

1.点击打开链接

2.点击打开链接

解题思路:评论区挺多大佬当搜索写了这题,自己学习STL大法过的,差距还是有的  努力啊。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;


int main()
{
	int a[1001],i,j,n,m;
	while(cin>>n>>m)
	{
		for(i=1;i<=n;i++)
			a[i]=i;
		for(i=1;i<m;i++)
			next_permutation(a+1,a+n+1);
		for(i=1;i<=n;i++)
		{
			cout<<a[i];
			if(i==n)
				cout<<endl;
			else
				cout<<" ";
		}
	}
	return 0;
}

next_permutation的使用:

#include<iostream>
#include<algorithm>
using namespace std;

/*

next_permutation(a,a+n):
每一次先判断a的前n个项是否逆序了,
是的话返回false;否则进入下一次排列

*/

int main()
{
	int a[1000]={1,3,2},i,j;
	do
	{
		for(i=0;i<3;i++)
			cout<<a[i]<<" ";
		puts("");
	}while(next_permutation(a,a+3));
	return 0;
}

/*
input:
a=1,2,3
a=1,3,2

output:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

*/


全部评论

相关推荐

king122:专业技能不要写这么多,熟悉和熟练你经不住问,排版有些难看,中间的空隙搞小一点,项目描述的话感觉是从课程中抄下来的,改一改吧,不然烂大街了,每个项目都写一两点,用什么技术实现了什么难点,然后再写一些数字上去像时间又花了90%这样,这样面试会多一些,如果觉得自己的项目还是不够用的话,我有几个大厂最近做过的实习项目,感兴趣的话可以看我简介中的项目地址
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务