A. Sequence with Digits

题目:样例:

输入
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7

输出
42
487
519
528
544
564
588
628

思路:

        暴力模拟题,看这数据范围,有些人可能会被唬住,以为是高精度或者容易超时,实际上,long long 型最多可以存储10^18次方,刚刚掐住这个数据范围点,所以我们直接用 long long 存储最后暴力模拟一遍即可,这里 ai 是 10^18次方,而我们需要取到当前位数最小的和最大的,我们可以将 ai 转换为字符串遍历一遍,就是 最多 循环 18 次,就可以取到相应的值,所以不用担心超时的。当我们取到 minx = 0 的时候,后面的 k 都是当前的 ai 了.

代码详解如下:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
#define endl '\n'
#define int long long
#define YES puts("YES")
#define NO puts("NO")
#define umap unordered_map
#define All(x) (x).begin(),(x).end()
#pragma GCC optimize(3,"Ofast","inline")
#define ___G std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e6 + 10;

inline void solve()
{
	long long num,k;
	cin >> num >> k;
	
	// 根据题意,我们的操作是要 --k 的
	while(--k)
	{
		string tem = to_string(num);
		
		// 定义相应的边界值,取到该位数的最大最小值
		int minx = 11;
		int maxx = -1;
		
		// 开始遍历取值
		for(auto i : tem)
		{
			minx = min(minx,(long long)i - '0');
			maxx = max(maxx,(long long)i - '0');
		}
		
		// 如果出现了位数最小值是 0 ,说明后面的 k - i 个数都是当前 ai
		// 退出循环即可
		if(!minx) break;
		
		// 操作获取 ai
		num += (maxx * minx);
	}
	
	// 输出操作后,ak 的值
	cout << num << endl;
}
signed main()
{
//	freopen("a.txt", "r", stdin);
	___G;
	int _t = 1;
	cin >> _t;
	while (_t--)
	{
		solve();
	}

	return 0;
}

最后提交:

用c++解决You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from 1 to N to each currency. Then each exchange point can be described with 6 numbers: integer A and B - numbers of currencies it exchanges, and real RAB, CAB, RBA and CBA - exchange rates and commissions when exchanging A to B and B to A respectively. Nick has some money in currency S and wonders if he can somehow, after some exchange operations, increase his capital. Of course, he wants to have his money in currency S in the end. Help him to answer this difficult question. Nick must always have non-negative sum of money while making his operations. Input The first line contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has. The following M lines contain 6 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces. 1 ≤ S ≤ N ≤ 100, 1 ≤ M ≤ 100, V is real number, 0 ≤ V ≤ 103. For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10-2 ≤ rate ≤ 102, 0 ≤ commission ≤ 102. Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence. You may assume that ratio of the numeric values of the sums at the end and at the beginning of any simple sequence of the exchange operations will be less than 104. Output If Nick can increase his wealth, output YES, in other case output NO.
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值