题目链接:http://codeforces.com/contest/792/problem/B 题意:告诉你有n个人围成一个圈,编号从1到n,一开始从1号开始,从2往逆时针方向数,数a[i]个人,然后这个人出局,从下一个人开始,总共有这样的k轮,然后让你输出出局的人的编号,其实看hint就应该能明白了 解析:我是直接开了个数组暴力模拟的,每个人的价值是1,出局就变成0,出局了就把他移到数组的后面(排序),大佬貌似使用vector维护的,好像会好写点
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+100; struct node { int v; int id; bool operator < (const node &b)const { if(v==b.v) return id<b.id; return v>b.v; } }a[maxn]; int main(void) { int n,k; scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) { a[i].v = 1; a[i].id = i; } int ans = 1,t = n; for(int i=1;i<=k;i++) { int x; scanf("%d",&x); sort(a+1,a+n+1); ans = (ans+x)%t; if(ans==0) ans = t; printf("%d ",a[ans].id); a[ans].v = 0; t--; } return 0; }