Run ID:111855
提交时间:2025-03-07 15:10:37
#include<bits/stdc++.h> using namespace std; int n,m;// n是人数,m是谁报道m谁死 int hz[1001];// hz[i]=1就表示是第i个人挂了,hz[i]=0表示第i个人活着 int main(){ cin >> n >> m; int ren =0; int bs = 0; int live = n;// 一开始活着的人是n个 int t; for(int j = 1;j <= n;j++){ cin >> hz[j]; } while(live != 1){ // 只要活着的人不是一个,游戏就得继续 ren++; if(ren == n+1){ // 如果是第n+1个人报的,其实就相当于是第1个人报 ren = 1; } if(hz[ren] == -2e9 || ren == 0){// 这个人已经挂了,跳过 continue; } bs++;// 没有跳过,说明该他报数 if(bs == m){ t = hz[ren]; m = hz[ren]; hz[ren] = -2e9;// 这个人噶了 cout << t <<" "; bs = 0; live--;// 活着的人少一 } } for(int i = 1;i <= n;i++){ if(hz[i] != -2e9){ cout << hz[i]; } } return 0; }