ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

B - Mysterious Resistors Gym - 102780B

2020-11-30 10:58:42  阅读:274  来源: 互联网

标签:Resistors double Gym mid value r1 Mysterious rk resistors


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有