1 条题解

  • 0
    @ 2024-8-2 16:19:44

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int cnt[30];//存储每个点的机会数
    int m,n;
    int main() {
    cin>>m;//猴子数量
    int x;
    for(int i = 1;i <= m;i++){
    cin>>x;
    if(x == 1) cnt[i] = 1;//1 次机会
    else cnt[i] = 2;//2 次
    }
    cin>>n;//出局数字
    int c = m;//目前猴子的总数
    int i = 0;
    x = 0;//要报的数字
    //当剩余猴子超过 1 个
    while(c > 1){
    i++;//逐个枚举
    //跳过淘汰的猴子
    while(cnt[i] == 0){
    i++;
    if(i > m) i = 1;
    }
    x++;//数数
    //i 号猴子数到了 n
    if(x == n){
    cnt[i]--,x = 0;//重新数数
    if(cnt[i] == 0) c--;
    }
    }
    for(int i = 1;i <= m;i++){
    if(cnt[i] > 0){
    cout<<i;
    break;
    }
    }
    return 0;
    }
    
    • 1

    信息

    ID
    992
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    3
    已通过
    3
    上传者