2 solutions

  • 1
    @ 2024-6-23 17:22:36

    模拟(95pts)

    • 使用队列模拟题目的过程,当数据达到10910^9次方会超时。
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        queue<int> q;
        for(int i=1;i<=n;i++) //编号放入队列 
        {
            q.push(i);
        }
        int cnt=0,res=1;
        while(true)
        {
            cnt++;
            queue<int> q1; //剩余的人 
            int m=q.size();
            for(int j=1;j<=m;j+=3) //每轮三个人 
            {
                int x=q.front();
                if(x==n) //编号为n的人 
                {
                    res=cnt;
                }
                q.pop(); //删除 
                if(q.size())q1.push(q.front()),q.pop(); //还有元素就入队 
                if(q.size())q1.push(q.front()),q.pop(); //还有元素就入队 
            }
            q=q1;
            if(q.size()==0) //没有元素就跳出 
            {
                break;
            }
        }
        cout<<cnt<<" "<<res<<endl;
        return 0;
    }
    

    找规律,

    • 每次少n/3上取整个人,而且只有当n%3==1的时候n就会被取走
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	cin>>n;
    	int days=0,date=0;
    	while(n)
    	{
    		days++;
    		if(!date&&n%3==1) date=days;
    		n-=(n+2)/3; //减去拿走的苹果数目 
    	}
    	cout<<days<<" "<<date;
    	return 0;
    }
    
    • 0
      @ 2024-6-30 10:55:29
      include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int n;
      	cin>>n;
      	int days=0,date=0;
      	while(n)
      	{
      		days++;
      		if(!date&&n%3==1) date=days;
      		n-=(n+2)/3; //减去拿走的苹果数目 
      	}
      	cout<<days<<" "<<date;
      	return 0;
      }👍 
      
      • 1

      Information

      ID
      1262
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      8
      Tags
      # Submissions
      16
      Accepted
      5
      Uploaded By