秒懂
2025-07-22 14:01:01
发布于:上海
6阅读
0回复
0点赞
非常好理解的办法
看作第一个之后每三个一次,
只剩不到三个时,
就只能拿走第一个,
总天数就计数就好了,
通过以上的性质,
那么,
第n个就是在第一次的最后一个被拿走时的天数。
#include<iostream>
using namespace std;
int main()
{
freopen("apple.in","r",stdin);
freopen("apple.out","w",stdout);
int n;
cin>>n;
int ans;
int day=1;
bool vis=true;
while(n)
{
if((n-1)%3==0&&vis)
{
ans=day;
vis=false;
}
if(n<3)
{
n--;
day++;
continue;
}
n=n-1-(n-1)/3;
day++;
}
cout<<day-1<<" "<<ans;
fclose(stdin);
fclose(stdout);
return 0;
}
这里空空如也
有帮助,赞一个