/*==========================================================*\
| 二分搜索答案
\*==========================================================*/
int main()
{
int n;
int cases = 1;
while (cin>>n, n != -1) {
int i, d[12], x;
double t[12], y;
for (i = 0; i < n; ++i)
cin>>d[i]>>t[i];
cin>>x>>y;
double low = 0.0, high = 1.0, sum = 0.0, mid;
while (MY_ABS(sum - y) > 0.000001) {
mid = (low + high) / 2;
sum = 0.0;
for (i = 0; i < n; ++i)
sum += t[i] * pow(mid + 1, x - d[i] + 1);
if (sum > y) high = mid;
else if (sum < y) low = mid;
else break;
}
printf("Case %d: %.5lf\n\n", cases++, mid);
}
return 0;
}
POJ-2199(一元n次方程,二分答案)(Rate of Return )
最新推荐文章于 2021-06-26 11:10:04 发布