5 条题解

  • 1
    @ 2026-5-17 22:12:05

    #include<bits/stdc++.h>

    #include

    using namespace std;

    int n,m;

    queue q;

    int main(){

    cin>>n>>m;
    
    for(int i=1;i<=n;i++){
    
    	q.push(i);
    
    }
    
    while(q.size()>1){
    
    	int i=m-1;
    
    	while(i--){
    
    		q.push(q.front());
      
    		q.pop();
      
    	}
    
    	q.pop();
    
    }
    
    cout<<q.front();
    
    return 0;
    

    }

    • -1
      @ 2025-5-14 13:08:17
      #include<bits/stdc++.h>
      using namespace std;
      int n,m,p[10086],cntd,cnt=1;
      int main(){
      	cin>>n>>m;
      	cntd=n; 
      	for(int i=1;i<=n;i++){
      		p[i]=i;
      	}//编号 
      	p[n+1]=-2;//碰到-2就重新从1开始数 
      	for(int i=1;cntd>1;i++){
      		if(p[i]==-2){
      			i=0;
      			continue;
      		}
      		if(p[i]==-1)continue;//被淘汰的跳过 
      		if(cnt%m==0){
      			p[i]=-1;
      			cntd--;//人数 
      		}//淘汰 
      		cnt++;
      	}
      	for(int i=1;i<=n;i++){
      		if(p[i]>0)cout<<p[i];
      	} 
      	return 0;
      } 
      
      
      • -1
        @ 2025-3-23 17:19:28
        #include<bits/stdc++.h>
        using namespace std;
        const int N=1e4+5,INF=0x3f3f3f3f;
        int heizi(int x,int y){
        	return x/y+(x%y!=0);
        }
        int n,q;
        int main()
        {
        	cin>>n>>q;
        	int d=1,end=(q-1)*n;
        	while(d<=end)d=heizi(q*d,q-1);
        	cout<<q*n+1-d;
        	return 0;
        }
        
        一定AC
        
        • -2
          @ 2022-11-17 15:23:24

          太简单了

          #include <iostream>
          using namespace std;
          bool a[1005];
          int main()
          {
          	int n,m,cnt=0,i=0,p=0;
          	cin >> n >> m;
          	while(i=i%n+1){
          //		cout << a[i] << " " << i << " " << cnt << " " << p << endl; 
          		if(cnt==n-1){
          			break;
          		}
          		if(a[i]==false){
          			p++;
          		}
          		if(p==m){
          			p=0;
          			a[i]=true;
          			cnt++;
          		}
          	}
          	for(int i = 1; i <= n; i++){
          		if(a[i]==false){
          			cout << i;
          			return 0;
          		}
          	}
          }
          
          • -3
            @ 2025-1-29 11:29:49

            这题本人有数学解法(不是模拟,太麻烦了,而且时间复杂度O(nm),数据大点就超时)

            其实还有一个时间复杂度O(m)的解法,但还是不够快

            ACcode(最快code)

            (复杂度本人也不会算)

            #include<bits/stdc++.h>
            using namespace std;
            const int N=1e4+5,INF=0x3f3f3f3f;
            typedef long long LL;
            LL ceil(LL x,LL y){
            	return x/y+(x%y!=0);
            }
            LL j(LL n,LL q){
            	LL d=1,end=(q-1)*n;
            	while(d<=end)d = ceil(q*d,q-1);
            	return q*n+1-d;
            }
            LL n,q;
            int main()
            {
            	cin>>n>>q;
            	cout<<j(n,q);
            	return 0;
            }
            

            有人能帮我算一下吗?(算出来私聊我)

            • 1

            信息

            ID
            1028
            时间
            1000ms
            内存
            32MiB
            难度
            6
            标签
            递交数
            428
            已通过
            127
            上传者