用python
from decimal import *
t = int(input())
for case in range(t):
with localcontext() as ctx:`加粗样式`
ctx.prec=600
n = int(input())
a = Decimal(sum(map(int,input().strip().split())))
b = Decimal(sum(map(int,input().strip().split())))
ans = a*b/n
print(format(ans,".30f"))
模拟除法
#include<iostream>
#include<stdio.h>
using namespace std;
void solve(long long ans,long long n)
{
long long res[32];
res[0]=ans/n;
ans=ans%n;
for (int i=1; i<=31; i++)
{
ans*=10;
res[i]=ans/n;
ans=ans%n;
}
if (res[31]>=5)
{
res[30]++;
for (int i=30; i>0; i--)
{
if (res[i]>=10)
{
res[i]=res[i]%10;
res[i-1]+=1;
}
}
}
printf("%lld.",res[0]);
for (int i=1; i<=30; i++)
{
printf("%lld",res[i]);
}
printf("\n");
}
int main()
{
long long t,n;
long long m;
cin>>t;
long long s1=0,s2=0;
while (t--)
{
scanf("%d",&n);
s1=0;
s2=0;
for (int i=1; i<=n; i++)
{
scanf("%lld",&m);
s1+=m;
}
for (int i=1; i<=n; i++)
{
scanf("%lld",&m);
s2+=m;
}
s1=s1*s2;
solve(s1,n);
}
return 0;
}
| |
- List item