P1080 wa70pts求调
  • 板块学术版
  • 楼主WaterM
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/2 23:52
  • 上次更新2023/11/2 16:25:34
查看原帖
P1080 wa70pts求调
943083
WaterM楼主2023/10/2 23:52
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define Linf 0x3f3f3f3f3f3f3f3f
#define re register
#define int long long
const int N = 1e3+2;

typedef class bigint {
public:
	static const int Base = 1e2;
	static const int Wid = 2;
	std::vector<int> a; 
public:
	bigint() {};
	bigint(char buf[]) {
		for(re int i = strlen(buf)-1; i >= 0; i -= Wid) {
			int num = 0;
			for(re int j = std::max(i-Wid+1, 0ll); j <= i; ++j) num = num * 10 + buf[j] - '0';
			a.push_back(num);
		}
	}
	
	int& operator[] (int p) {	//重载下标运算符
		return a[p];
	}
	int size() {
		return a.size();
	}
	void resize(int sz) {
		a.resize(sz, 0);
	}
	int turn_to_int() {
		int res = 0;
		for(re int i = a.size()-1; i >= 0; --i) res = res*10 + a[i];
		return res;
	}
	
	
	void shrink() {	//去除前导零
		while(a.size() > 1 && !a.back()) a.pop_back();
	}
	friend bool operator< (bigint a, bigint b) {
		if(a.size() != b.size()) return a.size() < b.size();
		for(re int i = a.size()-1; i >= 0; --i)
			if(a[i] != b[i]) return a[i] < b[i];
		return false;
	}
	friend bigint operator+ (bigint a, bigint b) {	//高精度加法
		a.resize(std::max(a.size(), b.size()) + 1);
		b.resize(a.size());
		for(re int i = 0; i < a.size() - 1; ++i) {
			a[i] += b[i];
			a[i+1] += a[i] / Base; 
			a[i] %= Base;
		}
		a.shrink();
		return a;
	}
	friend bigint operator* (bigint a, bigint b) {	//高精度乘法
		bigint c;
		c.resize(a.size() + b.size());
		for(re int i = 0; i < a.size(); ++i)
			for(re int j = 0; j < b.size(); ++j) 
				c[i+j] += a[i] * b[j];
		for(re int i = 0; i < c.size()-1; ++i) {
			c[i+1] += c[i] / Base;
			c[i] %= Base; 
		}
		c.shrink();
		return c;
	}
	friend bigint operator/ (bigint a, int b) {
		bigint c;
		c.resize(a.size());
		for(re int i = c.size() - 1; ; --i) {
			c[i] = a[i]/b;
			if(i == 0) break;
			a[i-1] += a[i]%b*Base;
		}
		c.shrink();
		return c;
	}
	
	friend std::istream& operator>> (std::istream& in, bigint &x) {
		char buf[5]; 
		in >> buf;
		x = bigint(buf);
		return in;
	}
	friend std::ostream& operator<< (std::ostream& out, bigint x) {
		out << x.a.back();
		for(re int i = x.size()-2; i >= 0; --i) printf("%02lld", x[i]);
		return out;
	}
};
bigint max(bigint x, bigint y) {
	return x < y ? y : x;
}

int n;
struct node {
	bigint x, y;
} a[N];
signed main() {
	std::cin >> n;
	for(re int i = 0; i <= n; ++i) std::cin >> a[i].x >> a[i].y;
	std::sort(a+1, a+n+1, [](node a, node b) {return a.x*a.y < b.x*b.y;});
	
	bigint res = a[0].x, ans = bigint("0");
	for(re int i = 1; i <= n; ++i) {
		ans = max(res / a[i].y.turn_to_int(), ans);
		res = res * a[i].x;
	}
	std::cout << ans;
    return 0;
}
2023/10/2 23:52
加载中...