---
title: 洛谷：P1088：火星人
url: 'https://rsywx.com/luogu/01088'
markdown: 'https://rsywx.com/luogu/01088.md'
date: '2026-10-01'
description: 'Table of contents: 题目 分析 答案 思考 …'
taxonomy:
  tag:
    - 排列组合
---

[  **Grav**  ](https://rsywx.com/) 

# 洛谷：P1088：火星人

 Posted on 1st Oct 2026

 ![洛谷：P1088：火星人](https://rsywx.com/images/6/e/6/6/0/6e660488331eff4aa07bfdfd939651bb61a02b62-solution.jpg "洛谷：P1088：火星人")
[P1088：火星人](https://www.luogu.com.cn/problem/P1088)

这道题目听起来很绕。但要注意到其中的描述：

> 如果把五根手指――拇指、食指、中指、无名指和小指分别编号为`1,2,3,4,5`，当它们按正常顺序排列时，形成了5位数12345，当你交换无名指和小指的位置时，会形成5位数12354，当你把五个手指的顺序完全颠倒时，会形成54321，在所有能够形成的120个5位数中，12345最小，它表示1；12354第二小，它表示2；54321最大，它表示120。

如果对上述的描述感觉“熟悉”，同时我们对比较小的数字的阶乘比较熟悉的话，就会想到：\\(P\_5^5=120\\)，也就是5个元素选择5个元素的全排列数量。

于是，我们要想到C++中的内置全排列函数`next_permutation`，它可以根据当前的排列状态，生成下一个全排列。

```cpp
next_permutation(fingers + 1, fingers + n + 1);
```

该函数的两个参数含义是一个左闭右开的区间。这里从`fingers+1`开始（因为我们用了1-基数组），到`fingers_n`结束（因为右边是开区间）。根据输入的`m`，循环求下一个即可。

![Solution](https://rsywx.com/user/pages/32.luogu/01088/solution.jpg)

这道题不难。掌握了内置函数`next_permutation`就可以。一些讨论，可以参见这个[帖子](https://blog.csdn.net/HowardEmily/article/details/68064377)。

   [排列组合](https://rsywx.com/tag:%E6%8E%92%E5%88%97%E7%BB%84%E5%90%88 "See other posts in 排列组合")

- 
- 
- 
- 

 [ Previous](https://rsywx.com/luogu/01087) [Next ](https://rsywx.com/luogu/01093)

---

## Navigation

- Parent: [洛谷练习](https://rsywx.com/luogu.md)
- Previous: [洛谷：P1087：FBI树](https://rsywx.com/luogu/01087.md)
- Next: [洛谷：P1093：奖学金](https://rsywx.com/luogu/01093.md)
