把浮点行转换成整数计算,避免精度的损失。
double l;
LL len;
int n;
int main()
{
int i;
LL sum = 0,a,b;
scanf("%lf %d",&l,&n);
len = l * 10000 + 0.5;
for (i = 0;i < n;i++) {
cin >> a >> b;
sum = (LL)(sum + (a * 10000 * b)%len) % len;
}
LL candidate = len - sum;
LL res = min(sum,candidate);
cout << res / 10000 << '.';
printf("%04I64d\n",res % 10000);
//printf("%04lld\n",res % 10000);
return 0;
}