Created
August 6, 2018 06:31
-
-
Save scott987/d8d79c7adaa6362f0b24e29abb4ba9cd to your computer and use it in GitHub Desktop.
Taiwan APCS 105-10-29 第3題 定時K彈 c++ vector 解法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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