uva - Magic Numbers(枚举、位运算)

方法:暴力枚举。

AC代码:

#include <iostream>        
#include <iomanip>        
#include <string>        
#include <cstring>        
#include <cstdio>        
#include <queue>        
#include <stack>        
#include <algorithm>        
#include <cmath>        
#include <ctime>    

using namespace std; 
const long long int maxn = 9876543210;

inline bool check(long long x)
{
	int i = 0, cnt = 0;
	while (x)
	{
		i = 1 << (x % 10);
		if (cnt & i)
			return false;
		cnt |= i;
		x /= 10;
	}
	return true;
}

int main()
{
	int t = 0;
	cin >> t;
	while (t--)
	{
		long long int x = 0, a = 0, b = 0;
		cin >> x;
		for (b = 1; b < maxn; b++)
		{
			a = b * x;
			if (a > maxn)
				break;
			else if (check(a) && check(b))
				cout << a << " / " << b << " = " << x << endl;
		}
		if (t)
			cout << endl;
	}
	return 0;
}
参考 : http://tech.ddvip.com/2013-12/1386686677206922.html 位运算的方法非常厉害不得不佩服,并且程序比想象的快了非常多。。但是不理解是硬伤,姑且先这样记住吧!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值