HDOJ 题目4394 Digital Square(DFS)

Digital Square

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1757    Accepted Submission(s): 677

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

2012 Multi-University Training Contest 10

Recommend

zhuyuanchen520   |   We have carefully selected several similar problems for you:  4390 4398 4397 4395 4393

ac代码

#include<stdio.h>
#include<string.h>
#define INF 1<<30
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
int a[20];
__int64 mod[20],ans,n,len;
void init()
{
	mod[0]=1;
	for(int i=1;i<20;i++)
	{
		mod[i]=mod[i-1]*10;
	}
}
void fun()
{
	__int64 temp=n;
	len=0;
	memset(a,0,sizeof(a));
	while(temp)
	{
		a[len++]=temp%10;
		temp/=10;
	}
}
void dfs(int now,int step)
{
	if(step==len)
	{
		ans=min(ans,now);
		return;
	}
	for(int i=0;i<=9;i++)
	{
		__int64 to,temp=now+mod[step]*i;
		to=temp;
		temp*=temp;
		temp/=mod[step];
		temp%=10;
		if(temp==a[step])
		{
			dfs(to,step+1);
		}
	}
}
int main()
{
	int t;
	init();
	scanf("%d",&t);
	while(t--)
	{
		scanf("%I64d",&n);
		fun();
		ans=INF;
		dfs(0,0);
		if(ans==INF)
		{
			printf("None\n");
		}
		else
			printf("%d\n",ans);
	}
}
时间: 2024-12-28 01:06:35

HDOJ 题目4394 Digital Square(DFS)的相关文章

HDU 4394 Digital Square

Digital Square Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1882    Accepted Submission(s): 741 Problem Description Given an integer N,you should come up with the minimum nonnegative integer

HDOJ 题目1501 Zipper(DFS)

Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7223    Accepted Submission(s): 2576 Problem Description Given three strings, you are to determine whether the third string can be formed

HDOJ 题目1088 滑雪(DFS,记忆化)

滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 80448   Accepted: 29995 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 17

Digital Square(hdu4394)搜索

Digital Square Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1310 Accepted Submission(s): 501 Problem Description Given an integer N,you should come up with the minimum nonnegative integer M.M me

hdoj 1045 Fire Net 【DFS】

题意:如果两个点要放在同一行或者同一列,那么两个点中间要有一个墙,否则的话只能放一个点,最后问你最多能放几个点. 看了一个星期.. 这道题的解法我还是第一次见,就是逐个逐个的来放置每个点,然后每经过一个点都判断一次,详情看代码 代码: #include <stdio.h> #include <string.h> int ans, n; char map[10][10]; int judge(int lin, int row) { int i; for(i = lin-1; i &g

HDOJ 题目4738 Caocao&#39;s Bridges(双联通,求桥)

Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1752    Accepted Submission(s): 642 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. B

HDOJ题目3729 I&#39;m Telling the Truth(二分图)

I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1629    Accepted Submission(s): 805 Problem Description After this year's college-entrance exam, the teacher did a survey i

HDOJ 题目分类

HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:    用STL中的next_permutation()1029:1032:1037:1039:1040:1056:1064:1065:1076:    闰年 1084:1085:1089,1090,1091,1092,1093,1094, 1095, 1096:全是A+B1108:1157:1196:1

HDOJ 题目3966 Aragorn&#39;s Story(Link Cut Tree成段加减点权,查询点权)

Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5505    Accepted Submission(s): 1441 Problem Description Our protagonist is the handsome human prince Aragorn comes from The Lor