ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces 792B Counting-out Rhyme

2020-01-29 14:07:25  阅读:300  来源: 互联网

标签:int Rhyme step 792B child eliminated Counting leader define


Codeforces 792B Counting-out Rhyme

Counting-out Rhyme
n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.

For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.

You have to write a program which prints the number of the child to be eliminated on every step.

Input
The first line contains two integer numbers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1).

The next line contains k integer numbers a1, a2, …, ak (1 ≤ ai ≤ 109).

Output
Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

Examples
input
7 5
10 4 11 4 1
output
4 2 5 6 1
input
3 2
2 5
output
3 2
Note
Let’s consider first example:

In the first step child 4 is eliminated, child 5 becomes the leader.
In the second step child 2 is eliminated, child 3 becomes the leader.
In the third step child 5 is eliminated, child 6 becomes the leader.
In the fourth step child 6 is eliminated, child 7 becomes the leader.
In the final step child 1 is eliminated, child 3 becomes the leader.
上代码

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(a) (int)((a).size())
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
#define see2(x,y) cout<<#x<<" = "<<x<<"::"<<#y<<" = "<<y<<endl
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int mod=1000000007;
typedef pair<int,int> pii;
const int maxn=1e5+5;
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n,k;
	cin>>n>>k;
	int a[n];
	oset s;
	for(int i=1;i<=n;i++){
		s.insert(i);
	}
	int cur=0;
	for(int i=0;i<k;i++){
		cin>>a[i];
		int dis=(cur+a[i])%sz(s);
		int to=*s.find_by_order(dis);
		cout<<to<<' ';
		cur=dis;
		s.erase(to);
	}
}

Selina Xu 发布了1 篇原创文章 · 获赞 1 · 访问量 20 私信 关注

标签:int,Rhyme,step,792B,child,eliminated,Counting,leader,define
来源: https://blog.csdn.net/Rex_Xing_yi_li/article/details/104106457

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有