Codeforces Round #499 (Div. 2) C. Fly 数学公式推导_codeforces c.fly-程序员宅基地

Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on
n

2
intermediate planets. Formally: we number all the planets from
1
to
n
.
1
is Earth,
n
is Mars. Natasha will make exactly
n
flights:
1

2


n

1
.

Flight from
x
to
y
consists of two phases: take-off from planet
x
and landing to planet
y
. This way, the overall itinerary of the trip will be: the
1
-st planet

take-off from the
1
-st planet

landing to the
2
-nd planet

2
-nd planet

take-off from the
2
-nd planet


landing to the
n
-th planet

the
n
-th planet

take-off from the
n
-th planet

landing to the
1
-st planet

the
1
-st planet.

The mass of the rocket together with all the useful cargo (but without fuel) is
m
tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that
1
ton of fuel can lift off
a
i
tons of rocket from the
i
-th planet or to land
b
i
tons of rocket onto the
i
-th planet.

For example, if the weight of rocket is
9
tons, weight of fuel is
3
tons and take-off coefficient is
8
(
a

i

8
), then
1.5
tons of fuel will be burnt (since
1.5

8

9
+
3
). The new weight of fuel after take-off will be
1.5
tons.

Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.

Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn’t need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.

Input
The first line contains a single integer
n
(
2

n

1000
) — number of planets.

The second line contains the only integer
m
(
1

m

1000
) — weight of the payload.

The third line contains
n
integers
a
1
,
a
2
,

,
a
n
(
1

a
i

1000
), where
a
i
is the number of tons, which can be lifted off by one ton of fuel.

The fourth line contains
n
integers
b
1
,
b
2
,

,
b
n
(
1

b
i

1000
), where
b
i
is the number of tons, which can be landed by one ton of fuel.

It is guaranteed, that if Natasha can make a flight, then it takes no more than
10
9
tons of fuel.

Output
If Natasha can fly to Mars through
(
n

2
)
planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number

1
.

It is guaranteed, that if Natasha can make a flight, then it takes no more than
10
9
tons of fuel.

The answer will be considered correct if its absolute or relative error doesn’t exceed
10

6
. Formally, let your answer be
p
, and the jury’s answer be
q
. Your answer is considered correct if
|
p

q
|
max
(
1
,
|
q
|
)

10

6
.

Examples
inputCopy
2
12
11 8
7 5
outputCopy
10.0000000000
inputCopy
3
1
1 4 1
2 5 3
outputCopy
-1
inputCopy
6
2
4 6 3 3 5 6
2 6 3 6 5 3
outputCopy
85.4800000000
Note
Let’s consider the first example.

Initially, the mass of a rocket with fuel is
22
tons.

At take-off from Earth one ton of fuel can lift off
11
tons of cargo, so to lift off
22
tons you need to burn
2
tons of fuel. Remaining weight of the rocket with fuel is
20
tons.
During landing on Mars, one ton of fuel can land
5
tons of cargo, so for landing
20
tons you will need to burn
4
tons of fuel. There will be
16
tons of the rocket with fuel remaining.
While taking off from Mars, one ton of fuel can raise
8
tons of cargo, so to lift off
16
tons you will need to burn
2
tons of fuel. There will be
14
tons of rocket with fuel after that.
During landing on Earth, one ton of fuel can land
7
tons of cargo, so for landing
14
tons you will need to burn
2
tons of fuel. Remaining weight is
12
tons, that is, a rocket without any fuel.
In the second case, the rocket will not be able even to take off from Earth.

自然是最后燃料全部用完是最优解,那么推导(乱搞)就好了;
( m+x )* ( 1- 1/a1 )* ( 1- 1/a2 )…( 1-1/an )( 1-1/b1 )( 1-1/b2 )…( 1-1/bn )== m
当然 其中的 ai,bi 有一个<=1,自然就是无解了;
将上述方程解出 x 即可;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>

typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 200005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-5
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}



double a[1005], b[1004];

int main()
{
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int i, j;
    int flag = 0;
    for (i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] <= 1.0)flag = 1;
    }
    for (i = 0; i < n; i++) {
        cin >> b[i];
        if (b[i] <= 1.0)flag = 1;
    }
    if (flag)cout << -1 << endl;
    else {
        double ans = 1.0;
        for (i = 0; i < n; i++) {
            ans = 1.0*ans*(a[i] / (a[i] - 1.0))*(b[i] / (b[i] - 1.0));
        }
        ans = (ans - 1.0)*m;
        printf("%.10f\n", 1.000000*ans);

    }

}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40273481/article/details/81238814

智能推荐

FANUC机器人INTP或251坐标系与示教资料不符报警的处理办法_intp-250(d19saw.ing,3)uf与教示资intp252 用户坐标系号码不相同-程序员宅基地

文章浏览阅读854次。在此示例中,我们首先定义了INTP的编号(INTP_ID)和新的INTP定义(NEW_INTP_DEF)。检查程序中的坐标系调用:如果在程序中使用了INTP或251坐标系,确保调用的坐标系与示教资料中的定义相匹配。检查程序中的相关指令,如"PR[用户坐标系编号]“和"PR[工具坐标系编号]”,以确保正确调用了相应的坐标系。检查示教资料:核对示教资料,包括用户坐标系(INTP)和工具坐标系(251)的定义。确保示教资料和坐标系设置的一致性,并检查程序中的坐标系调用,以确保正确使用INTP和251坐标系。_intp-250(d19saw.ing,3)uf与教示资intp252 用户坐标系号码不相同

uni-app使用微信JSSDK_jweixin.js下载-程序员宅基地

文章浏览阅读6.1k次。uni-app使用微信JSSDK安装jweixin-module引用jweixin-module接口获取wx.configwx.config 初始化(写到 methods里)使用安装jweixin-moduleNPM安装方式(不会用NPM就不要用这种方式)npm install jweixin-module --save下载使用方式下载地址:https://unpkg.com/[email protected]/lib/index.js引用jweixin-module//mi_jweixin.js下载

python输出1到100整数_python第一个代码程序打印1到100整数-程序员宅基地

文章浏览阅读9.8k次。原博文2019-05-30 07:36 −def main(): #打印1到100的整数 i=1 while i_输出一到一百所有的数python

LoRa---SX1278_sx1278 fsk配置-程序员宅基地

文章浏览阅读2.4k次。LoRa—SX1278LoRa介绍sx1278支持FSK GFSK MSK GMSK LoRa OOK调制,分为Lora调制解调器和FSK/OOK调制解调器,根据选定的模式可以选择传统的FSK/OOK调制技术或Lora扩频调制技术,这里对主要对Lora模式做一些介绍。LoRa是一个基于线性调制的无线网络标准。线性调制:线性调制代表“压缩高强度雷达脉冲”,这是一个频率随时间增加或者减少的..._sx1278 fsk配置

mtk6592处理器怎么样,mtk6592参考设计原理图下载-程序员宅基地

文章浏览阅读2.9k次。首先说一下mtk6592,联发科MT6592是联发科股份科技有限公司基于2013年7月份发布的的全球首款商用量产同步八核智能机系统单芯片。MT6592由8颗Cortex-A7核心构成,采用台积电28nm工艺,最高频率可达2GHz。MT6592的GPU已确认为mail 450 mp4,该GPU同频率同核心性能约为mail 400 mp4的两倍,GPU频率性能ARM Mali450-MP4图像内核,7..._mtk6592

大一计算机基础实用教程答案第二章,《计算机基础实用教程》答案-程序员宅基地

文章浏览阅读103次。第1章1.4.习题1. 电子计算机的发展阶段通常以构成计算机的电子器件来划分,至今已经历了四代,目前正在向第五代过渡。1.第一代——电子管计算机(1946-1957年)第一代计算机采用的主要原件是电子管,称为电子管计算机。2.第二代——晶体管计算机(1958-1964年)晶体管的发明给计算机技术的发展带来了革命性的变化。第二代计算机采用的主要元件是晶体管,称为晶体管计算机。3.第三代——集成电路计..._计算机实用技术大一

随便推点

ROS学习历程(1)-----在ubuntu 15.10 安装ROS Kinetic_ubuntu 15.10 ros-程序员宅基地

文章浏览阅读1.6k次。1.ubuntu 15.10 安装与使用安装镜像下载地址:http://www.ubuntu.com/download/desktop下载后,使用U盘启动安装,安装后设置更新源等,并配置常用的应用。 2.ROS kinetic安装与使用参考的网址: http://wiki.ros.org/kinetic http://wiki.ros.org/kinetic/Installation_ubuntu 15.10 ros

IDEA 中 project和module的关系_idea module-程序员宅基地

文章浏览阅读2.3w次,点赞45次,收藏92次。作为小白,开发工具刚从Eclipse转到IDEA。在IDEA中不能像eclipse那样直接在一个workspace下复制粘贴项目。很容易出错。首先,在IDEA里面并没有workspace这个东西。IDEA里可以把Project认为是最高的存储目录。在Project里又可以创建module。module,即模块、组件。我们可以在每个module里完成特定的功能,(相当于eclipse里的proj..._idea module

关于三角形外心性质的探究_三角形外心的性质-程序员宅基地

文章浏览阅读3k次。标题 三角形外心的性质 当还在高中的你遇到三角形外心性质的问题,是不是很揪心呢 那今天就交给大家一个绝招,hhhhhhh16340129 数据科学与计算机学院 一、三角形外心问题? 1.这个不多说啦,有图有问题,而且这类题一般都和向量有关 在这里涉及在外心O,即三角形三边的垂直平分线的交点,下面我..._三角形外心的性质

forEach循环报java.lang.NullPointerException空指针异常_集合不为空,foreach报空指针异常-程序员宅基地

文章浏览阅读1.1k次。一、测试1、最近对接SDK 发现项目中List<Object>.forEach老报空指针异常这个原因是因为返回的时候返回为null导致遍历出错。 public static void main(String[] args) { List<String> strings = null; strings.forEach(System.out::println); }..._集合不为空,foreach报空指针异常

handle句柄 matlab_谁能系统且简要地介绍一下matlab中的function handle吗?-程序员宅基地

文章浏览阅读327次。如果你学过其他的编程语言的话,类比可能会让你更好地理解什么是function handle(“函数句柄”,这个翻译太难听了)。Matlab里面function handle类似于python里面的函数对象、C++语言里面的函数指针、Perl里面的函数引用。function handle可以将function包装操作成(handle)一个变量。一个函数变成了一个变量之后,则我们可以在另外一个函数的参..._matlab中fun4_1是什么

【Redis】GEO(地理坐标)数据结构_geo坐标-程序员宅基地

文章浏览阅读2.1k次,点赞2次,收藏2次。GEO就是Geolocation的简写形式,代表地理坐标。Redis在3.2版本中加入了对GEO的支持,允许存储地理坐标信息,帮助我们根据经纬度来检索数据。一个点评平台,有多个频道,每个频道都有很多个店铺。我们按照频道类型做分组,相同频道的店铺作为同一组,以频道id为key存入同一个GEO集合中即可。其中,Value值存储店铺的id。_geo坐标