Educational Codeforces Round 18 B
Description
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.
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).
Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.
7 5
10 4 11 4 1
4 2 5 6 1
3 2
2 5
3 2
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.
题意:n个学生,我们从0开始数ai个数字,输出下一个数字,然后删除输出的数字,数到的数字作为新的起点再次循环这个操作,好乱啊,看Note吧
解法:模拟
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 ll n,m; 5 ll a[300000]; 6 ll maxn=(1<<31)-1; 7 vector<ll>q; 8 bool fun(int i) 9 { 10 return (i > 0) && ((i & (i - 1)) == 0); 11 } 12 int main() 13 { 14 string s; 15 cin>>n>>m; 16 for(ll i=1;i<=n;i++) 17 { 18 q.push_back(i); 19 } 20 ll ans=0; 21 for(ll i=1;i<=m;i++) 22 { 23 cin>>a[i]; 24 ll x=(a[i]%q.size()+ans)%q.size(); 25 cout<<q[x]<<" "; 26 ans=x; 27 q.erase(q.begin()+x); 28 } 29 return 0; 30 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~