高精度运算题

114. 国王游戏 - AcWing题库

思路非常简单, 主要是他没有给数据, 卡了一下。

然后还要学一下大数运算

 

/*//
Problem: 114. 国王游戏
Contest: 贪心
URL: https://www.acwing.com/problem/content/116/
/*/


// 要用大数运算, 怪不得一直卡我
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;

class DaShu {
  public:
	vector<int > mul (vector<int > a, int b) {
		vector<int > res;
		int t = 0;
		for (int i = 0; i < a.size(); i ++) {
			t += a[i] * b;
			res.push_back(t % 10);
			t /= 10;
		}
		while (t > 0) {
			res.push_back(t % 10);
			t /= 10;
		}
		return res;
	}

	vector<int > div (vector<int > a, int  b) {
		vector<int > res;
		int t = 0;
		bool flag = false;
		for (int i = a.size() - 1; i >= 0; i --) {
			t = t * 10 + a[i];
			int tmp = t  / b;
			if (tmp || flag) {
				flag = true;
				res.push_back(tmp);
			}
			t %= b;
		}
		return vector<int > (res.rbegin(), res.rend());
	}

	vector<int > add (vector<int > a, vector<int > b) {
		vector<int > res;
		return res;
	}

	vector<int > rdu (vector<int > a, vector<int > b) {
		vector<int > res;
		return res;
	}

	vector<int > _max (vector<int > a, vector<int > b) {
		if (a.size() > b.size()) {
			return a;
		} else if (b.size() > a.size()) {
			return b;
		} else {
			if (vector<int >(a.rbegin(), a.rend()) > vector<int >(b.rbegin(), b.rend())) {
				return a;
			} else {
				return b;
			}
		}
	}
};

struct node {
	friend bool operator<(node x1, node x2) {
		return x1.v < x2.v;
	}
	ll v, l, r;
};

int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(0);     cout.tie(0);
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	vector<node> t;
	for (int i = 0; i < n; i ++) {
		node tmp;
		cin >> tmp.l >> tmp.r;
		tmp.v = (ll)tmp.l  *  tmp.r;
		t.push_back(tmp);
	}

	sort(t.begin(), t.end());
	vector<int > sum;
	vector<int > res;
	sum.push_back(a);
	DaShu daShu;
	daShu.mul(sum, b);
	for (int i = 0; i < n; i ++) {
		res = daShu._max(res, daShu.div(sum, t[i].r));
		sum = daShu.mul(sum, t[i].l);
	}

	for (int i = res.size() - 1; i >= 0; i --) {
		if (i)
			cout << res[i];
		else
			cout << res[i] << endl;
	}
	return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值