牛客OI周赛14-普及组--2Number

牛客OI周赛14-普及组----2Number

链接:https://ac.nowcoder.com/acm/contest/4479/B
来源:牛客网

在这里插入图片描述
在这里插入图片描述
最大次方我定在20,pow(2,20)>10e6,,,
貌似复杂度不是很大,暴力应该没问题

依题意,赶快暴力吧,,,

#include <iostream>
#include <cmath>
using namespace std;
//
int res(int a, int i)
{//pow(0,0)结果为1 ,所有再定义一个保证 pow(0,0) = 0;
	if (a == 0)
		return 0;
	else return pow(a, i);
}
//
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int max = 20;
	int n;
	while (cin >> n)
	{
		int count = 0;
		while (n--)
		{
			int x;
			cin >> x;
			int a1, a2, a3, a4, a5, a6, a7;
			//计算出每一位的数值
			a1 = x % 10;
			a2 = x / 10 % 10;
			a3 = x / 100 % 10;
			a4 = x / 1000 % 10;
			a5 = x / 10000 % 10;
			a6 = x / 100000 % 10;
			a7 = x / 10e6;
			//
			int tmp = 0;
			int aa1, aa2, aa3, aa4, aa5, aa6, aa7;
			for (int i = 0; i <= max;++i)
			{//每一位数进行次方
				aa1 = res(a1, i);
				aa2 = res(a2, i);
				aa3 = res(a3, i);
				aa4 = res(a4, i);
				aa5 = res(a5, i);
				aa6 = res(a6, i);
				aa7 = res(a7, i);
				tmp = aa1 + aa2 + aa3 + aa4 + aa5 + aa6 + aa7;
				//一旦超过即跳出,(以后会更大)
				if (tmp >= x)
					break;
			}
			if (tmp == x)	++count;
		}	
		cout << count << '\n';
	}
	return 0;
}

总体来说,本题难度不是很大,直接求解就O了;

如需改进,希望大家批评指正。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值