Digital Square

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1827    Accepted Submission(s):
714

Problem Description
Given an integer N,you should come up with the minimum
nonnegative integer M.M meets the follow condition:
M2%10x=N (x=0,1,2,3....)
 
Input
The first line has an integer T( T< = 1000), the
number of test cases.
For each case, each line contains one integer N(0<=
N <=109), indicating the given number.
 
Output
For each case output the answer if it exists, otherwise
print “None”.
 
Sample Input
3
3
21
25
 
Sample Output
None
11
5
 
Source
 
Recommend
zhuyuanchen520   |   We have carefully selected several
similar problems for you:  4390 4398 4397 4396 4395 
 
搜索题,首先证明出N位后缀只与M的后N位有关。比如三位数100a+10b+c平方后展开为 10000a^2+2000ab+100b^2+200ac+20bc+c^2很显然,平方后的最后一位只与c有关最后两位只与bc有关,最后三位abc都有关。
那我们只需要BFS一下,不断地找满足最后指定位数的数,1位,2位,……直到找到第一个满足条件的。
 
题意:给出n,求出最小的m,满足m^2  % 10^k = n,其中k=0,1,2
 
附上代码:
 
 #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)的更多相关文章

  1. Digital Square(hdu4394)搜索

    Digital Square Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU 1372 Knight Moves (bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Othe ...

  3. HDU 2102 A计划(BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...

  4. HDU 1728 逃离迷宫(BFS)

    Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有 ...

  5. HDU 4394 Digital Square

    Digital Square Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. HDU 1254 推箱子(BFS)

    Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不 ...

  7. 【HDU - 3085】Nightmare Ⅱ(bfs)

    -->Nightmare Ⅱ 原题太复杂,直接简单的讲中文吧 Descriptions: X表示墙 .表示路 M,G表示两个人 Z表示鬼 M要去找G但是有两个鬼(Z)会阻碍他们,每一轮都是M和G ...

  8. HDU 2102 A计划 (BFS)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. HDU - 1973 - Prime Path (BFS)

    Prime Path Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. OpenLayers使用弹出窗口

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  2. Vue.之. 动态设置按钮Disabled

    Vue.之. 动态设置按钮Disabled 按钮代码如下: 添加了一个 属性      :disabled="isAble"  ,控制:更新按钮.重置按钮 <el-form- ...

  3. vs dump调试

    1. dump文件和pdb文件的匹配问题 >> 发布二进制文件时生成的pdb文件一定要保留,只有当发布的二进制文件和pdb文件是同时生成的才好正确调试. 2. dump文件和pdb文件放在 ...

  4. 【JZOJ3824】【NOIP2014模拟9.9】渴

    SLAF 世界干涸,Zyh认为这个世界的人们离不开水,于是身为神的他要将他掌控的仅仅两个水源地放置在某两个不同的城市.这个世界的城市因为荒芜,他们仅仅保留了必要的道路,也就是说对于任意两个城市有且仅有 ...

  5. BigDecimal创建初始化值类型对比

    当初始化String类型和double类型,入参值相同,对比输出值 BigDecimal bigDecimalStr = new BigDecimal("0.1"); BigDec ...

  6. 关闭myeclipse可视化视图

    ctrl+w  关闭各个文件  重新打开即可 方法二:

  7. 搜索docker镜像

    docker最简单的方式莫过于从现有的容器镜像开始. Docker官方网站专门有一个页面来存储所有可用的镜像,网址是:index.docker.io. 可以通过浏览这个网页来查找你想要使用的镜像,或者 ...

  8. LeetCode103 Binary Tree Zigzag Level Order Traversal

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  9. ubuntu18.10 安装pycurl

    sudo apt-get install libcurl3 sudo apt-get install libcurl4-openssl-devsudo apt-get install python3 ...

  10. hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】

    https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...