高精度运算题

高精度运算题,第1张

高精度运算

114. 国王游戏 - AcWing题库

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

然后还要学一下大数运算

 



// 要用大数运算, 怪不得一直卡我
#include 
#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 mul (vector a, int b) {
		vector 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 div (vector a, int  b) {
		vector 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 (res.rbegin(), res.rend());
	}

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

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

	vector _max (vector a, vector b) {
		if (a.size() > b.size()) {
			return a;
		} else if (b.size() > a.size()) {
			return b;
		} else {
			if (vector(a.rbegin(), a.rend()) > vector(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 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 sum;
	vector 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;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3970565.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-21
下一篇 2022-10-21

发表评论

登录后才能评论

评论列表(0条)

保存