跳到正文

题解

P9748

Xdwjs约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年10月22日
收录
2026年10月24日
更新
2026年11月7日
篇幅
约 1 分钟
获赞
9
题目
P9748

版本

  1. v1当前

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

Code:

C++
#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;
}
原文
存档评论1 条抓取于