60分求助
  • 板块P1988 火炬
  • 楼主__erinww
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/7/27 12:35
  • 上次更新2023/11/3 07:25:06
查看原帖
60分求助
850498
__erinww楼主2023/7/27 12:35

从P2841过来的,复制一下代码,稍微改了一下,只得了60分。。。(迭代加深搜索)

这是代码↓

#include <stdio.h>

#define int __int128

int STEP = 1;
int n,len;
bool flag = true;
static inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
static inline void write(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
	putchar(x%10+'0');
    return;
} 
static inline bool IDDFS(int x,int y,int deep){
	if(y%x == 0) return write(y/x),true;//,putchar(' '),write(y),true;
	if(deep >= STEP) return false;
	return (IDDFS(x,y*10+1,deep+1) || IDDFS(x,y*10,deep+1));
}

signed main(){
	n = read();
	while(!IDDFS(n,1,0)) STEP ++;
    return 0;
}
2023/7/27 12:35
加载中...