P8588雷雨天特别行动科求助!
  • 板块学术版
  • 楼主zpc2011
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/10/26 12:04
  • 上次更新2023/10/27 05:50:03
查看原帖
P8588雷雨天特别行动科求助!
806897
zpc2011楼主2022/10/26 12:04

第一个对,第二个不对,为什么?

#include<bits/stdc++.h>
using namespace std;
long long x,k;
int sz[2]={2,1};
int main(){
	cin>>x>>k;
	while(k>0&&x>=3){
		x++;
		if(x%3==0) x/=3;
		k--;
	}
	if(k==0) cout<<x;
	else cout<<sz[k%2];
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
long long x,k;
int sz[2]={2,1};
int main(){
	cin>>x>>k;
	while(1){
		x++;
		if(x%3==0) x/=3;
		k--;
		if(k==0) break;
		if(x<3) break;
	}
	if(k==0) cout<<x;
	else cout<<sz[k%2];
	return 0;
}
2022/10/26 12:04
加载中...