题意: 一辆车共有 n 行座位,一行有 4 个,左右分别有 2 个,人是先将这 n 行
座位的左右各一个靠窗位置坐满,再坐靠近过道的位置,下车时先下左边靠近
过道位置的人再下靠近窗户的人,同理接着下右边的人,按上车的人先坐的行
开始下车。(先左后右,编号从 1--m 共 m 个人)
思路:直接模拟。
*/
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;
#define inf 0x3f3f3f3f
int main()
{
#ifdef OFFLINE
freopen("t.txt", "r", stdin);
#endif
int n, m, i, j, k, tmp;
while (~scanf("%d%d", &n, &m))
{
if (m <= 2 * n){//人只坐靠窗位置
for (i = 1; i < m; i++){
printf("%d ", i);
}
printf("%d\n", m);
}
else{
int row = (m - 2 * n) / 2;//除了靠窗位置每行有2个过道位置,算出需几行
if ((m - 2 * n) % 2) row++;//不整除时加 1
tmp = 2 * n + 1;//过道位置起始标号
for (i = 1; i < row; i++){//前 row-1 行都是每行坐满 4 人
printf("%d %d %d %d", tmp, 2 * i - 1, tmp + 1, 2 * i);
tmp += 2;
printf(" ");
}
if ((m - 2 * n) % 2 == 0)//第 row 行满人
printf("%d %d %d %d", tmp, 2 * row - 1, tmp + 1, 2 * row);
else if ((m - 2 * n) % 2 == 1)//第 row 行缺一个
printf("%d %d %d", tmp, 2 * row - 1, 2 * row);
for (i = row + 1; i <= n; i++){//row 往上的行都只坐靠窗位置
printf(" %d %d", 2 * i - 1, 2 * i);
}
printf("\n");
}
}
return 0;
}