URAL 1495 One-two, One-two 2 (BFS)
来源:互联网 发布:联通云计算公司工资 编辑:程序博客网 时间:2024/06/01 08:17
#include <stdio.h>int N;typedef struct Node{char num[32];int mod;}Node;Node queue[1000000];int visited[1000001];char *str = "012";int head, tail;int strLen(char *str){char *p = str;while (*p != '\0')p++;return p - str;}void strCpy(char *to, char *from){while (*from != '\0'){*to = *from;from++;to++;}*to = '\0';}int main(){scanf("%d", &N);head = tail = 0;Node nodePushed;nodePushed.num[0] = '\0';nodePushed.mod = 0;queue[tail++] = nodePushed;while (head < tail){Node nodePoped = queue[head++];int len = strLen(nodePoped.num);if (len > 30)break;int i;for (i = 1; i <= 2; i++){int mod;mod = (nodePoped.mod * 10 + i) % N;if (visited[mod])continue;//为什么这样做标记可以剪枝?visited[mod] = 1;char num[32];strCpy(num, nodePoped.num);num[len] = str[i];num[len + 1] = '\0';if (mod == 0){printf("%s\n", num);return 0;}Node nodePushed;strCpy(nodePushed.num, num);nodePushed.mod = mod;queue[tail++] = nodePushed;if (head > tail)printf("The queue is overflow\n");}}printf("Impossible\n");return 0;}
0 0
- URAL 1495 One-two, One-two 2 (BFS)
- URAL 1495. One-two, One-two 2 DP or BFS?
- URAL 1495. One-two, One-two 2
- URAL 1495. One-two, One-two 2
- 【构造】 URAL 1495 One-two, One-two 2
- 算法练习:URAL 1495 One-two, One-two 2
- URAL 1495. One-two, One-two 2(暴力枚举)
- Timus 1495. One-two, One-two 2
- URAL 1216 Two Pawns and One King
- One or Two
- test one two three
- Two minus one 游戏规则
- Two minus one Rules
- 12289 - One-Two-Three
- one+two问题
- one,two,three
- 算法练习2:Two fighters, one winner.
- 4-2-Two Stacks In One Array
- RHEL7 CENTOS7
- strcpy和memcpy的区别
- Android 沉浸式状态栏攻略 让你的状态栏变色吧
- Oracle数据库时间与字符串转换
- Effective C++——必须返回对象时,别妄想返回其引用或指针
- URAL 1495 One-two, One-two 2 (BFS)
- Android学习笔记之AndroidManifest.xml文件解析
- 深入Java单例模式
- 深入浅出单实例Singleton设计模式
- linux命令详解:df & du命令
- MyBatis入门学习教程 MyBatis快速入门
- -Dmaven.multiModuleProjectDirectory system propery is not set.
- hdu5464 Clarke and problem(DP)
- 深入理解virtual,abstract class,interface