其他分享
首页 > 其他分享> > B - Mysterious Resistors Gym - 102780B

B - Mysterious Resistors Gym - 102780B

作者:互联网

When repairing an electronic board, Basil discovered that the board had already been under repair, and one of the resistors on it was replaced with a strange design. The design consisted of k

series of connected links, and each link in them — of two resistors connected in parallel.

Moreover, in each link, along with the typical resistor, with a clearly readable denomination, there was a resistor with a strange, non-standard marking. Having examined the non-standard resistors, Basil came to the conclusion that they were of the same type. However, he could not determine their value. The total resistance value of the entire circuit was equal to R ohms. Having written out the nominal value of the known resistor for each link in the circuit, Basil received a series of integers r1, r2, ..., rk.

Help Basil — write a program that calculates the value of the mysterious resistors from the total resistance of the circuit R

, and the known values r1, r2, ..., rk

.

Input

The first line of the input data contains two integers k

(1≤k≤1000) and R (1≤R≤100000

), separated by a space.

The second line contains k

integers separated by spaces: r1, r2,..., rk (1≤ri≤100000; 2R≤r1+r2+…+rk

).

Output

The program should output a single number — the estimated value of the mysterious resistors. The value must be outputed with an accuracy of 10−6

.

Examples

Input

3 11
3 12 30

Output

6.00000000

Input

7 110
15 60 6 45 20 120 70

Output

30.00000000

Note

Recall that while connecting two resistors with the values of R1

and R2, the total resistance R is calculated as R=R1+R2 for the serial connection, and as 1R=1R1+1R2 for the parallel one.

题解:二分查找电阻是否符合。

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using namespace std;
#define INF 0x3f3f3f3f
#define Max 1000001
int n;
double m;
double r[1001];
double g(double x)
{
   int i;
   double ans=0;
   for(i=0;i<n;i++)
   {
      ans=ans+x*r[i]/(r[i]+x);
   }
   return ans;
}
double find1(double l,double r)
{
    if(l>r)
    {
       return 0;
    }
    double mid=(l+r)/2;
    double ans=g(mid);//mid就是所检验的电阻
    if(abs(ans-m)<0.000000001)
    {
       return mid;
    }
    if(ans>m)
    {
        return find1(l,mid);
    }
    else
    {
        return find1(mid,r);
    }
}
int main()
{
    scanf("%d %lf",&n,&m);
    int i;
    for(i=0;i<n;i++)
    {
       scanf("%lf",&r[i]);
    }
    double sum=find1(0,100000);
    printf("%.8lf\n",sum);
    return 0;
}

 

标签:Resistors,double,Gym,mid,value,r1,Mysterious,rk,resistors
来源: https://blog.csdn.net/m0_46062697/article/details/110378013