I. 洗牌
知识点:数组、模拟
直接暴力模拟就行。
标程
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
array<int, 54> a;
iota(a.begin(), a.end(), 1);
int n;
cin >> n;
while (n--)
{
int l, r;
cin >> l >> r;
--l;
rotate(a.begin(), a.begin() + l, a.begin() + r);
}
for (auto x : a)
cout << x << ' ';
cout << '\n';
}
Java
import java.util.*;
import java.io.*;
public class Main {
static Kattio io = new Kattio();
public static void main(String[] args) {
int a[] = new int[60];
int b[] = new int[60];
for (int i = 1; i <= 54; i++) {
a[i] = i;
}
int n = io.nextInt();
for (int i = 0; i < n; i++) {
int l = io.nextInt(), r = io.nextInt();
for (int j = l; j <= r; j++) {
b[j - l + 1] = a[j];
}
for (int j = 1; j < l; j++) {
b[j + r - l + 1] = a[j];
}
for (int j = r + 1; j <= 54; j++) {
b[j] = a[j];
}
for (int j = 1; j <= 54; j++) {
a[j] = b[j];
}
}
for (int i = 1; i <= 54; i++) {
io.print(a[i] + " ");
}
io.close();
}
}
class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// 标准 IO
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// 在没有其他输入时返回 null
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) {}
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
Python
a = list(range(1, 55))
n = int(input())
for _ in range(n):
l, r = map(int, input().split())
l -= 1
a = a[l:r] + a[:l] + a[r:]
print(*a)