首页 > 代码库 > Blacklist
Blacklist
题意: 给出一个16进制数(long long),找出比他大的第一个16进制数
搜索题,看似水,却是水。
简单题可是别想复杂了
#include <cstdio>#include <cstring>char ch[20];int a[20];bool pd[20];int len;bool dfs(int p, bool boom){ if(p==len) return 1; int t=a[p]; if(boom) t=0; for(int i=t; i<16; i++) if(!pd[i]) { pd[i]=1; a[p]=i; if(dfs(p+1,boom|i>t)) return 1; pd[i]=0; } return 0;}void print(){ for(int i=0; i<len; i++) if(a[i]<=9) printf("%d",a[i]); else printf("%c",a[i]-10+‘A‘);}int main(){ unsigned long long n; scanf("%llX",&n); sprintf(ch,"%llX",++n); len=strlen(ch); for(int i=0; i<len; i++) if(ch[i]>=‘0‘&&ch[i]<=‘9‘) a[i]=ch[i]-‘0‘; else a[i]=ch[i]-‘A‘+10; if(dfs(0,0)) print(); else { memset(a,0,sizeof(a)); len++; a[0]=1; pd[1]=1; dfs(1,1); print(); } return 0;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。