hdu 4394 Digital Square(bfs)
Digital Square
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1827 Accepted Submission(s):
714
nonnegative integer M.M meets the follow condition:
M2%10x=N (x=0,1,2,3....)
number of test cases.
For each case, each line contains one integer N(0<=
N <=109), indicating the given number.
print “None”.
similar problems for you: 4390 4398 4397 4396 4395
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
__int64 n;
struct node
{
__int64 a;
int x;
friend bool operator < (node n1,node n2) //优先队列,必须输出最小的数
{
return n1.a>n2.a;
}
} s1,s2; void BFS()
{
priority_queue <node> q;
while(!q.empty())
q.pop();
__int64 t;
s1.a=;
s1.x=;
q.push(s1);
while(!q.empty())
{
s1=q.top();
q.pop();
t=(__int64)pow(10.0,s1.x); //从低位向高位搜
if(s1.a*s1.a%t==n) //找到了就直接输出
{
printf("%I64d\n",s1.a);
return;
}
for(int i=; i<; i++)
{
s2.x=s1.x+; //每次都向前进一位
s2.a=s1.a+i*t;
if(s2.a*s2.a%(t*)==n%(t*)) //一位一位的匹配,匹配成功后,则放入队列
q.push(s2);
}
}
printf("None\n");
}
int main()
{
int T,m,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
if(n%==||n%==||n%==||n%==) //根据乘法的规律,任何一个数平方后的个位数不可能是这些数
{
printf("None\n");
continue;
}
BFS();
}
return ;
}
hdu 4394 Digital Square(bfs)的更多相关文章
- Digital Square(hdu4394)搜索
Digital Square Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1372 Knight Moves (bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 2102 A计划(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...
- HDU 1728 逃离迷宫(BFS)
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有 ...
- HDU 4394 Digital Square
Digital Square Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1254 推箱子(BFS)
Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不 ...
- 【HDU - 3085】Nightmare Ⅱ(bfs)
-->Nightmare Ⅱ 原题太复杂,直接简单的讲中文吧 Descriptions: X表示墙 .表示路 M,G表示两个人 Z表示鬼 M要去找G但是有两个鬼(Z)会阻碍他们,每一轮都是M和G ...
- HDU 2102 A计划 (BFS)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU - 1973 - Prime Path (BFS)
Prime Path Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- 从0开始学习 GitHub 系列之「06.团队合作利器 Branch」
Git 相比于 SVN 最强大的一个地方就在于「分支」,Git 的分支操作简直不要太方便,而实际项目开发中团队合作最依赖的莫过于分支了,关于分支前面的系列也提到过,但是本篇会详细讲述什么是分支.分支的 ...
- AndroidStudio离线打包MUI
1.下载5+SKD http://ask.dcloud.net.cn/article/103 2.解压到任意目录 3.导入HBuilder-Hello项目 4.在AndroidManifest.xml ...
- 2-2 Numpy-矩阵
# !usr/bin/env python # Author:@vilicute import numpy as np # 矩阵的创建 matr1 = np.mat("4 2 3;4 5 6 ...
- Spring Boot:Boot2.0版本整合Neo4j
前面介绍了Boot 1.5版本集成Neo4j,Boot 2.0以上版本Neo4j变化较大. 场景还是电影人员关系 Boot 2.0主要变化 GraphRepository在Boot2.0下不支持了,调 ...
- java 日期合法
try { String date_str = "5555-22-33"; SimpleDateFormat format=new SimpleDateFormat("y ...
- NOIP模拟 7.05
Problem 1 双色球(ball.cpp/c/pas) [题目描述] 机房来了新一届的学弟学妹,邪恶的chenzeyu97发现一位学弟与他同名,于是他当起了善良的学长233 “来来来,学弟,我考你 ...
- mac上SVN的图形工具 SmartSVN注册
mac上SVN的图形工具 SmartSVN注册 打开smartsvn,选中license注册 选中文件smartsvn.license,下一步下一步就ok了 smartsvn.license Name ...
- Mysql+php报错原因
SQL syntax --语法错误,看near,错误会在near后引号中的内容 的附近 Table/Database....... dosen't existes ---表/库(库名/表名) 不存在 ...
- ThinkPHP5.0中的build.php自动生成所需的目录结构的详细方法
一.来到根目录下,找到bulid.php文件进行改写. 改写方法:保留常用的目录结构,其余按照需求改吧! 二.复制一份build.php文件到application目录下 此时根目录下的bulid.p ...
- golang数据类型二
字符类型 3.14基本数据类型的相互转换 3.15基本数据类型和string的转换 FormatInt // FormatUint 将 int 型整数 i 转换为字符串形式// base:进位制(2 ...