HDU 4325 Vampire Numbers

本文介绍了一种寻找吸血鬼数字(Vampire Numbers)的方法,并提供了C语言及C++两种实现方式,通过预处理生成所有符合条件的吸血鬼数字并对其进行排序,最后针对每个输入查找最近的大于或等于输入的吸血鬼数字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Vampire Numbers

Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 437 Accepted Submission(s): 210


Problem Description

The number 1827 is an interesting number, because 1827=21*87, and all of the same digits appear on both sides of the ‘=’. The number 136948 has the same property: 136948=146*938.
Such numbers are called Vampire Numbers. More precisely, a number v is a Vampire Number if it has a pair of factors, a and b, where a*b=v, and together, a and b have exactly the same digits, in exactly the same quantities, as v. None of the numbers v, a or b can have leading zeros. The mathematical definition says that v should have an even number of digits and that a and b should have the same number of digits, but for the purposes of this problem, we’ll relax that requirement, and allow a and b to have differing numbers of digits, and v to have any number of digits. Here are some more examples:
126 = 6 * 21
10251 = 51 * 201
702189 = 9 * 78021
29632 = 32 * 926
Given a number X, find the smallest Vampire Number which is greater than or equal to X.

Input

There will be several test cases in the input. Each test case will consist of a single line containing a single integer X (10 ≤ X ≤ 1,000,000). The input will end with a line with a single 0.

Output

For each test case, output a single integer on its own line, which is the smallest Vampire Number which is greater than or equal to X. Output no extra spaces, and do not separate answers with blank lines.

Sample Input

  
10 126 127 5000 0

Sample Output

  
126 126 153 6880

Source


C语言实现

//题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4235
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int cmp(const void *a, const void *b)
{ return *(int *)a - *(int *)b;}

int main (void)
{
	int ans[1000];
	int temp[10];
	int i , j, k, s, n, count ,flag;
	int temp_s, temp_i, temp_j;
	count = 0;
	for(i = 1; i <= 1010; i++)                  //前一个约数(小的)
		for(j = i ; j < 1000500 / i; j++)   //后一个约数(大的)
		{
			s = i * j;             
			temp_s = s; 
			temp_i = i;
			temp_j = j;

			memset(temp,0,sizeof(temp));
		   
			while(temp_s){temp[temp_s%10]++; temp_s /= 10;}
			while(temp_i){temp[temp_i%10]--; temp_i /= 10;}
			while(temp_j){temp[temp_j%10]--; temp_j /= 10;}

			flag = 1;
			for(k = 0; k < 10; k++)
				if(temp[k])
				{flag = 0;break;}

				if(flag)  
					ans[count++] = s;
		}

		qsort(ans,count,sizeof(ans[0]),cmp);   

		while(scanf("%d", &n)!=EOF)
		{
		     if(!n) return 0;

			 for(i = 0;i <= 712; i++)
			    if(n <= ans[i])
				{
				     printf("%d\n", ans[i]);
				     break;
				}
			 
		}
	return 0;
}


C++ 实现

#include<cstdio>
#include<string>
#include<set>
#include <numeric>
#include <algorithm>

using namespace std;

int main(void)
{
   int i, j, n, s;
   int a, b, c, num[10];
   set<int> vampire;

   for(i = 1; i < 1010; i++)    //较小约数
   {
       for(j = i; j < 1001000 / i ; j++)    //另一个约数
       {
           s = i * j;    //可能成为Vampire Numbers的数
           a = s; b = i; c = j;
           memset(num, 0, sizeof(num));
           while(a) { num[a % 10]++; a /= 10; }
           while(b) { num[b % 10]--; b /= 10; }
           while(c) { num[c % 10]--; c /= 10; }
           if(find_if(num, num + 10, bind2nd(not_equal_to<int>(), 0)) == num + 10)    //如果是Vampire Numbers则保存
               vampire.insert(s);
       }
   }
   while(scanf("%d", &n) && n){
       printf("%d\n", *vampire.lower_bound(n));
   }
   return 0;
}


PS:以上这两种实现的思路都是一样的,弱菜没有想出来,是看了同学的代码之后才感到此思路实在不错,遂同大家分享。C++实现的代码是老师给的,代码运用了STL使得更加短小精悍,特此推荐。


内容概要:本文系统介绍了基于C#(VS2022+.NET Core)与HALCON 24.11的工业视觉测量拟合技术,涵盖边缘提取、几何拟合、精度优化及工业部署全流程。文中详细解析了亚像素边缘提取、Tukey抗噪算法、SVD平面拟合等核心技术,并提供了汽车零件孔径测量、PCB焊点共面性检测等典型应用场景的完整代码示例。通过GPU加速、EtherCAT同步等优化策略,实现了±0.01mm级测量精度,满足ISO 1101标准。此外,文章还探讨了深度学习、量子启发式算法等前沿技术的应用前景。 适合人群:具备一定编程基础,尤其是熟悉C#和HALCON的工程师或研究人员,以及从事工业视觉测量与自动化检测领域的技术人员。 使用场景及目标:①学习如何使用C#和HALCON实现高精度工业视觉测量系统的开发;②掌握边缘提取、抗差拟合、3D点云处理等核心技术的具体实现方法;③了解工业部署中的关键技术,如GPU加速、EtherCAT同步控制、实时数据看板等;④探索基于深度学习和量子计算的前沿技术在工业视觉中的应用。 其他说明:本文不仅提供了详细的理论分析和技术实现,还附有完整的代码示例和实验数据,帮助读者更好地理解和实践。同时,文中提到的硬件选型、校准方法、精度验证等内容,为实际项目实施提供了重要参考。文章最后还给出了未来的技术演进方向和开发者行动建议,如量子-经典混合计算、自监督学习等,以及参与HALCON官方认证和开源社区的建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值