Skip to content

Instantly share code, notes, and snippets.

@t1089
Forked from scott987/定時K彈_vector.cpp
Created February 5, 2021 01:05
Show Gist options
  • Select an option

  • Save t1089/b74be6c8217becee4f87ecfe49effbba to your computer and use it in GitHub Desktop.

Select an option

Save t1089/b74be6c8217becee4f87ecfe49effbba to your computer and use it in GitHub Desktop.
Taiwan APCS 105-10-29 第3題 定時K彈 c++ vector 解法
#include <cstdio>
#include <vector>
using namespace std;
vector<int> member;
int main()
{
int N,M,K;
scanf("%d %d %d",&N,&M,&K);
//建立成員列表並位每一位成員編碼
member.resize(N);
for(int i=0;i<N;++i)
{
member[i]=i+1;
}
int now=0;
//每次把淘汰者從陣列中排除
for(int i=0;i<K;++i)
{
//找到下一位淘汰者
now=(now+M-1)%member.size();
//將淘汰者從列表排除
member.erase(member.begin()+now);
}
printf("%d\n",member[now%member.size()]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment