比赛 |
2025暑期集训第7场 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Power Calculus |
最终得分 |
100 |
用户昵称 |
李金泽 |
运行时间 |
3.514 s |
代码语言 |
C++ |
内存使用 |
1.62 MiB |
提交时间 |
2025-08-11 15:48:19 |
显示代码纯文本
#include<cstdio>
#define N 1005
using namespace std;
int n,a[N],step;
bool dfs(int now,int t)
{
if(now>n*2)return 0;
if((t==step&&now^n)||now<0||(now<<step-t)<n)return 0;
if(now==n||(now<<step-t)==n)return 1;
a[t]=now;
for(int i=0;i<=t;i++)
if(dfs(now+a[i],t+1))return 1;
else if(dfs(now-a[i],t+1))return 1;
return 0;
}
int main(){
freopen("pow_cal.in","r",stdin);freopen("pow_cal.out","w",stdout);
while(~scanf("%d",&n))
{
if(!n)return 0;
for(step=0;!dfs(1,0);step++);
printf("%d\n",step);
}
return 0;
}