P9748

· · 题解

注意到编号为 n 的苹果如果存在,只会排在最后一个,所以我们不需要完全模拟每一轮的删除,只需要算出每一轮删除后的剩余苹果数量即可。

Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sy,cnt=0,ans=1;
    cin>>n;
    sy=n;
    while(sy>=1)
    {
        int tmp=sy/3;
        if(sy%3>=1) tmp++;
        sy-=tmp;
        cnt++;
    }
    while(n%3!=1)
    {
        int tmp=n/3;
        if(n%3>=1) tmp++;
        ans++;
        n-=tmp;
    }
    cout<<cnt<<" "<<ans;
    return 0;
}