# c296: APCS-2016-1029-3定時K彈 題目連結:[c296](https://zerojudge.tw/ShowProblem?problemid=c296) 我很單純的用一個迴圈來執行題目所說的流程 就是每次計算會爆炸的人然後淘汰 但是如果只使用陣列來模擬很難處理 因為移除的後面的成員要往前接 例如:1-2-3-4-5-1 如果移除2 就會要分兩個步驟處理 1- -3-4-5-1 然後將後面接上 1-3-4-5-1 所以我使用vector 以下為程式碼: ```c= #include<stdio.h> #include<vector> #include<iostream> using namespace std; int main(){ int n,m,k; vector<int> v; while(scanf("%d%d%d",&n,&m,&k)!=EOF){ int i; for(i=0;i<n;i++){ v.push_back(i+1); } int now=0; for(i=0;i<k;i++){ now=(now+m-1)%v.size(); //printf("%d now=%d %d\n",i+1,now,v[now]); v.erase(v.begin()+now); } now=now%v.size(); printf("%d\n",v[now]); v.clear(); } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up