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. POJ 2311 博弈

    #include<stdio.h> #include<string.h> #include<set> using namespace std; ][]; int s ...

  2. LintCode_14 二分查找

    题目 给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. 样例 在数组 [1 ...

  3. 笔记:投机和投资 F4NNIU

    笔记:投机和投资 F4NNIU 投机是零和交易. 投资是正和博弈. 投机看是短期,只关心当下. 投资是看的长期,更关注未来. 投机容易分散注意力. 投资更关心交易外的注意力. 投机像是看运气,运气有好 ...

  4. python装饰器2

    装饰模式有很多经典的使用场景,例如插入日志.性能测试.事务处理等等,有了装饰器,就可以提取大量函数中与本身功能无关的类似代码,从而达到代码重用的目的.下面就一步步看看Python中的装饰器. 一个简单 ...

  5. Java Map 排序

    1. 按照key值排序 对于java中Map的排序,有排序Map,比如TreeMap,对于这个Map,首先只能按照键排序,其次再put和remove的时候由于需要排序,性能上会有所牺牲. 这种方案,使 ...

  6. @划水记@ THUWC2020 (?)

    目录 @day -1@ @day 0@ @day 1@ @day 2@ @day 2+@ @day 3@ @day ?@ @day -1@ 听闻 THUWC 在 12 月举行的消息,突然就停了大概一周 ...

  7. AGC029 E: Wandering TKHS

     E: Wandering TKHS - AtCoder Grand Contest 029 | AtCoder 分类讨论好题(也不太算分类讨论) 方法:感受过程手玩,考虑能不能提前预算一些东西,或者 ...

  8. importError: DLL load failed when import matplotlib.pyplot as plt

    importError: DLL load failed when import matplotlib.pyplot as plt 出现这种情况的原因, 大多是matplotlib的版本与python ...

  9. 13条必知必会&&测试

    1.13条必知必会 <> all(): 查询所有结果 <> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <> get(**kwargs) ...

  10. iOS打包上传ipa文件时,报错<ERROR ITMS-90096: "Your binary is not optimized for iPhone 5 - New iPhone apps......>的解决方案

    很长一段时间习惯了用企业级证书发布,最近的新项目使用Xcode 9.1发布到AppStore时遇到了一个小问题(emm..其实问题跟Xcode版本没关系,我也不知道为什么要声明这个233),如下: E ...