当前位置:网站首页>【SSL集训DAY1】A【BFS】
【SSL集训DAY1】A【BFS】
2022-08-06 11:58:00 【VL——MOESR】

思路:
和几天前集训的题一模一样。
上次打深搜,这次打广搜
c o d e code code
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int n;
queue<pair<int, string> > q;
bool v[1000010];
int main() {
scanf("%d", &n);
q.push(make_pair(1, "1"));
v[1] = 1;
while(!q.empty()) {
int r = q.front().first;
string ss = q.front().second;
q.pop();
int g = r * 10 % n;
if(!v[g]) {
v[g] = 1;
q.push(make_pair(g, ss + "0"));
if(g == 0) {
cout<<ss + "0";
return 0;
}
}
g = (r * 10 + 1) % n;
if(!v[g]) {
v[g] = 1;
q.push(make_pair(g, ss + "1"));
if(g == 0) {
cout<<ss + "1";
return 0;
}
}
}
cout<<-1;
return 0;
}
边栏推荐
猜你喜欢
随机推荐
PG核心技术篇--表中系统字段
教你画像素画每周分享195期
Kubernetes 集群故障案例
d重载操作符
PHP fopen write file content
HCIP Day 15 Notes
太强了,一个注解搞定接口返回数据脱敏!
1408. String Matching in Arrays: Simple Simulation Questions
ES6 new feature - generator
Offer harvester!The giant's latest interview guide, quick to see see!
黑马程序员Request&Response
《ABP Framework 极速开发》 - 教程首发
PS6603-USB PD 协议 SINK 端输出控制器芯片
Chat about dynamic proxy IP
PBJ | 浙大马斌/茶叶所徐平-微生物组关联分析茶树-微生物遗传机制
NITZ时区更新空口消息
Kubernetes stain and tolerance
LeetCode high frequency question 75. Color classification: Dutch flag question
剧照怎么找?哪里获取高清资源?这9个网站渠道相见恨晚! 原创
在常州“超级虚拟工厂”,中国智造正在“原力觉醒”









