Skip to main content
  1. Posts/

poj 1833 排列

·313 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://poj.org/problem?id=1833

还是next_permutation.

这次是Int类型的

需要注意的是next_permutation是先判断时候有后继,返回一个bool值,如果为true,就转化到后继。

而next_permutation函数本书不考虑其值,就具有转化成后继的作用。

而且默认最后一个排列的下一个排列是第一个排列。

Details
 1
 2
 3    /* ***********************************************
 4    Author :111qqz
 5    Created Time :2016年02月19日 星期五 15时43分58秒
 6    File Name :1833.cpp
 7    ************************************************ */
 8
 9    #include <algorithm>
10    #include <cstdio>
11    #include <iostream>
12    #include <cstring>
13    #include <string>
14    #include <cmath>
15    #include <map>
16
17    using namespace std;
18    const int N=3E3+5;
19    int n ,m,k;
20    int a[N],b[N];
21
22    int main()
23    {
24        cin>>m;
25        while (m--)
26        {
27            cin>>n>>k;
28          //  k = k % n;
29
30            for ( int i = 0;i < n ; i++ )
31            {
32                scanf("%d",&a[i]);
33            }
34            while (k--)
35            {
36                next_permutation(a,a+n);
37            }
38            for ( int i = 0 ; i < n ; i++ )
39            {
40                printf("%d ",a[i]);
41            }
42            printf("\n");
43
44
45        }
46
47
48    	return 0;
49    }

Related

poj 1256 Anagram

·249 words·1 min
http://poj.org/problem?id=1256 题意是说求出一个字符串的全排列,按字典序 需要注意的是字典序和传统意义上的字典序不同

codeforces 548B Mike and Fun

·440 words·1 min
http://codeforces.com/problemset/problem/548/B 比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。

poj 2492 A Bug's Life (并查集)

·399 words·1 min
http://poj.org/problem?id=2492 Hint Huge input,scanf is recommended. 也是带种类的冰茶几。 由于只分了两类…我们还是可以按照上道题的做法。。

poj 1703 Find them, Catch them (并查集)

·536 words·2 mins
http://poj.org/problem?id=1703 种类冰茶几…看到还有一种算是拓展的交加权冰茶几? 看到有做法是在开一个数组。。。记录是哪一组…. 但是因为只有两组….我们可以分别存… 因为不知道每一个D的两个人分别是哪个组(帮派?) 可以都存一下。 TLE了两次….应该是用了cin的事。。。改成scanf就变WA了。。。 想了下。原来是我对“not sure yet”的判断出现失误。 我开了一个v数组,记录在D下出现的人。 我误以为出现的人的帮派一定是确定的。 实际上并不是。 比如 1,3 5,7 3和7都出现了。但是3和7是一组与否显然还是“not sure yet”