HDOJ 4394 —— BFS
来源:互联网 发布:pdm产品数据管理软件 编辑:程序博客网 时间:2024/04/30 15:16
Digital Square
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 830 Accepted Submission(s): 349
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.
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
332125
Sample Output
None115
Source
2012 Multi-University Training Contest 10
Recommend
zhuyuanchen520
题意是给你一个N,让你输出最小的M使得 M^2 % 10^x = N
我们从最低位向高位去搜,如果 M^2 % 10^y = N % 10^y 则将之加入队列。
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <map> #include <string> #include <stack> #include <cctype> #include <vector> #include <queue> #include <set> #include <utility> using namespace std; //#define Online_Judge #define outstars cout << "***********************" << endl; #define clr(a,b) memset(a,b,sizeof(a)) #define lson l , mid , rt << 1 #define rson mid + 1 , r , rt << 1 | 1 //#define mid ((l + r) >> 1) #define mk make_pair #define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++) #define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++) #define REP(i , x , n) for(int i = (x) ; i > (n) ; i--) #define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--) const int MAXN = 100000 + 50; const long long LLMAX = 0x7fffffffffffffffLL; const long long LLMIN = 0x8000000000000000LL; const int INF = 0x3f3f3f3f; const int IMIN = 0x80000000; const double E = 2.718281828; #define eps 1e-8 #define DEBUG 1 #define mod 100000007 typedef long long LL; const double PI = acos(-1.0); typedef double D; typedef pair<int , int> pi; // #pragma comment(linker, "/STACK:102400000,102400000")__int64 a[10050]; struct Node { __int64 m , x; Node() { m = 0; x = 0; } }; __int64 ten[10]; void init() { __int64 num = 1; FOR(i , 0 , 10) { ten[i]= num; num *= 10; } } __int64 getlength(__int64 x) { if(x == 0)return 1; int num = 0; while(x > 0) { x /= 10; num++; } return num; } int main() { int t; __int64 n; cin >> t; init(); while(t--) { scanf("%I64d" , &n); int len = getlength(n); queue <Node> q; q.push(Node());// outstars while(!q.empty()) { Node u = q.front();// q.pop();// outstars if(u.x == len) { break; }// outstars FOR(i , 0 , 10) { Node v ; v.m = u.m + ten[u.x] * i; v.x = u.x + 1;// outstars if((v.m * v.m) % ten[v.x] == n % ten[v.x]) {// outstars q.push(v);// outstars } } q.pop();// outstars }// outstars __int64 ans = INF; while(!q.empty()) { Node u = q.front(); q.pop(); if(ans > u.m)ans = u.m; } if(ans == INF)printf("None\n"); else printf("%I64d\n" , ans); } return 0; }
- HDOJ 4394 —— BFS
- HDOJ ——2102(bfs)
- HDOJ 1241 Oil Deposits——邻接矩阵BFS和DFS
- HDOJ 1253 ——胜利大逃亡 三维BFS
- hdoj 1242 Rescue(bfs)
- HDOJ 1072 Nightmare (bfs)
- HDOJ 2364 Escape (bfs)
- hdoj 2364 Escape(BFS)
- HDOJ 1072 Nightmare bfs
- Hdoj 1424 Rescue 【BFS】
- hdoj 1242 Rescue (BFS)
- hdoj Asteroids! (BFS)
- hdoj 1242 Rescue [BFS]
- hdoj 5040 bfs
- hdoj 1072 Nightmare 【bfs】
- HDOJ 1242 Rescue【BFS】
- hdoj 5335 bfs
- hdoj 1242 Rescue 【bfs】
- TCP/IP底层原理
- 有木有像我一样被科幻片中各种未来电脑系统迷得不行的小伙伴们?
- Java/Android的class与implements
- STL源码剖析_读书笔记:第四章 序列式容器 queue篇
- 经典计算机书籍记录
- HDOJ 4394 —— BFS
- eclipse部署web项目至本地的tomcat但在webapps中找不到
- char与varchar的区别?
- 任务分配的最优方案
- java集合类总结
- UVa 543 Goldbach's Conjecture (素数&哥德巴赫猜想)
- 组队赛131004 Regionals 2010, North America - East Central NA
- J2EE中统计当前在线人数——HttpSessionBindingListener和HttpSessionListener
- socket的recv非常慢,为什么?