60求大佬帮改,写了高精度,悬赏关注
查看原帖
60求大佬帮改,写了高精度,悬赏关注
531731
playerqwq楼主2023/9/21 21:43

错误pts#5#7#8#9 code

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll n,aw,bw,nw[10505],ln,calc[10505],lc,mx[10505],lm,clc,res[10505],lr;
struct node{
	ll a,b;
}dc[1005];
bool cmp(node x,node y){
	if(x.a * x.b == y.a * y.b)return x.a < y.a;
	return x.a * x.b < y.a * y.b;
} 
void print(ll x[],ll &len){
	while(x[len - 1] == 0 && len > 1)--len;
	while(x[len])++len;
	for(int i = len - 1;i >= 0;--i)cout << x[i];
	cout << endl;
	return;
}
ll dmx(ll a[],ll &la,ll b[],ll &lb){
	while(a[la - 1] == 0 && la > 1)--la;
	while(b[lb - 1] == 0 && lb > 1)--lb;
	while(a[la])++la;
	while(b[lb])++lb;
	if(la >lb)return 1;
	if(la <lb)return 2;
	for(int i = la - 1;i >= 0;--i){
		if(a[i] > b[i])return 1;
		if(a[i] < b[i])return 2;
	}
	return 2;
}
int main(){
	scanf("%lld%lld%lld",&n,&aw,&bw);
	for(int i = 1;i <= n;++i)scanf("%lld%lld",&dc[i].a,&dc[i].b);
	sort(dc + 1,dc + n + 1,cmp);
	nw[0] = aw,ln = lm = 1;
	for(int j = 0;j < 10;++j)nw[j + 1] += nw[j] / 10,nw[j] %= 10;
	for(int i = 1;i <= n;++i){
//		cout << dc[i].a <<" " <<dc[i].b << endl;
		for(int j = 0;j < ln + 400;++j)nw[j +1] += nw[j] / 10,nw[j] %= 10;
		while(nw[ln] != 0)++ln;
//		print(nw,ln);
		memset(res,0,sizeof(res));
		lr = ln,clc = 0;
		for(int j = ln - 1;j >= 0;--j){
			clc = clc * 10 + nw[j];
			res[j] += clc / dc[i].b,clc %= dc[i].b;
		}
//		print(res,lr);
		ll rr = dmx(res,lr,mx,lm);
		if(rr == 1){
			for(int j = lr - 1;j >= 0;--j)mx[j] = res[j];
			lm = lr;
		}
		for(int j = ln - 1;j >= 0;--j){
			nw[j] *= dc[i].a;
		}
	}
	print(mx,lm);	
	return 0;
}

悬赏关注

2023/9/21 21:43
加载中...