当前位置:网站首页>Blue Bridge Cup - provincial tournament - with points
Blue Bridge Cup - provincial tournament - with points
2022-07-22 21:45:00 【ai_ moe】
List of articles
Topic details
Solution code
#include<iostream>
#include<cstring>
using namespace std;
int n;
bool st[20],backup[20];
int ans;
bool check(int a,int c)
{
long long b = n * (long long) c-a*c;
if(!a || !b || !c) return false;
memcpy(backup,st,sizeof st);
while(b)
{
int x=b%10;
b=b/10;
if(!x || backup[x]) return false;
backup[x]=true;
}
for(int i =1;i<=9;i++)
if(!backup[i]) return false;
return true;
}
void dfs_c(int u,int a,int c)
{
if(u>9) return;
if(check(a,c)) ans++;
for(int i=1;i<=9;i++)
{
if(!st[i])
{
st[i]=true;
dfs_c(u+1,a,c*10+i);
st[i]=false;
}
}
}
void dfs_a(int u,int a)
{
if(a>=n) return ;
if(a) dfs_c(u,a,0);
for(int i=1;i<=9;i++)
{
if(a>n) return;
if(!st[i])
{
st[i]=true;
dfs_a(u+1,a*10+i);
st[i]=false;
}
}
}
int main()
{
cin >> n;
dfs_a(0,0);
cout << ans;
return 0;
}
边栏推荐
猜你喜欢
自动化测试Json通用解析器
Relationship and difference between session and cookie
C# Winform开发 WinAppDriver 自动测试的使用
10. System information related commands
Winappdriver automatic test deployment of WinForm automatic test
Binance Chinese community x cartesi AMA review
水庫河道應急廣播系統解决方案
Web编程入门 AdminLTE框架的使用
蓝桥杯-地宫取宝
Reinstalled NVIDIA graphics driver
随机推荐
蓝桥杯-省赛-翻硬币
ES6的常用语法
7-1 detailed steps of installing SSH on virtual machine
水庫河道應急廣播系統解决方案
新生儿,脑区分割资料
Run pychar on the server. Prompt: already running
C语言实现strlen的三种方法
[PROBLEMS] idea running war package project
ImageView ScaleType解惑
Blue Bridge Cup - half chocolate
水库河道应急广播系统解决方案
关于char与short类型的整形提升,以及使用和打印时原反补的转换
与 Cartesi 联合创始人一起喝杯咖啡
蓝桥杯-K倍区间
C# Winform开发 窗体间的数据交互
锡盟蒙古族中学校园有线电视光纤传输系统设计剖析
记录:问题1,电脑闪屏;问题2,电脑桌面图标双击没有反应
Solve problems encountered when compiling mosquitto
Binance 华语社区 x Cartesi AMA 回顾
Serialization and deserialization of C WinForm development data