求大佬帮忙看下问题
  • 板块题目总版
  • 楼主DYF2024
  • 当前回复5
  • 已保存回复5
  • 发布时间2025/2/5 13:07
  • 上次更新2025/2/5 16:41:37
查看原帖
求大佬帮忙看下问题
1584005
DYF2024楼主2025/2/5 13:07

https://www.luogu.com.cn/record/201380587

P1010 [NOIP 1998 普及组] 幂次方

在洛谷上面AC了,但是上传到另一个OJ就WA了,有一个测试点没过。

代码:

#include<iostream>
using namespace std;
void S(int n) {
	if(n==0)cout<<"0";
	else if(n==1)cout<<"2(0)";
	else if(n==2)cout<<"2";
	else {
		bool first=true;
		for(int i=14; i>=0; i--) {
			if((1<<i)<=n) {
				if(!first)cout<<"+";
				if(i==1)cout<<"2";
				else {
					cout<<"2(";
					S(i);
					cout<<")";
				}
				n-=(1<<i);
				first=false;
			}
		}
	}
}
int main() {
	int n;
	cin>>n;
	S(n);
	return 0;
}

另一OJ评测记录:https://boyacoding.cn/record/67a2f0180d81591877805938

题目链接:https://boyacoding.cn/p/A0094

2025/2/5 13:07
加载中...