noip模拟赛 对刚
3
分析:约瑟夫环问题,可以用链表模拟做,也可以套用公式,比较水.
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n, t, l[100010], r[100010], st = 1; int main() { scanf("%d%d", &n, &t); for (int i = 1; i <= n; i++) { l[i] = i - 1; r[i] = i + 1; if (i == 1) l[i] = n; if (i == n) r[i] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j < t; j++) st = r[st]; int t = st; st = r[st]; l[r[t]] = l[t]; r[l[t]] = r[t]; } printf("%d\n", st); return 0; }