【第一届“文翁杯”现场竞技赛】T4—文翁的难题

传送门

如果知道了并想到了对数的话就是水题了

由于对数良好的性质log(ab)=log(a)+log(b)log(a*b)=log(a)+log(b)

所以我们可以将乘转化为对数来比较大小

结果开始因为精度炸了好多次233…

#include<bits/stdc++.h>
using namespace std;
#define eps 1e-9
int n,a[100005],b[100005];
long double x[100005],y[100005];
inline int read(){
	char ch=getchar();
	int res=0,f=1;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
	return res;
}
signed main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read(),b[i]=read();
		x[1]+=log((double)a[i]),y[1]+=log((double)b[i]);
		if(x[1]+eps>y[1]&&y[1]+eps>x[1])puts("equal");
		else if(x[1]+eps>y[1])puts("A");
		else if(y[1]+eps>x[1])puts("B");
	}
	
}
原文地址:https://www.cnblogs.com/stargazer-cyk/p/10366318.html