CodeForces1010A Fly

C. Fly Codeforces Round #499 (Div. 2) C. Fly 题目链接 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Natasha is going to fly on a rocket to Mars and return to Earth. Also... 阅读详情

题目传送门:http://codeforces.com/problemset/problem/1010/A

output

standard output

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−2n−2 intermediate planets. Formally: we number all the planets from 11 to nn. 11 is Earth, nn is Mars. Natasha will make exactly nn flights: 1→2→…n→11→2→…n→1.

Flight from xx to yy consists of two phases: take-off from planet xx and landing to planet yy. This way, the overall itinerary of the trip will be: the 11-st planet →→ take-off from the 11-st planet →→ landing to the 22-nd planet →→ 22-nd planet →→ take-off from the 22-nd planet →→ …… →→ landing to the nn-th planet →→ the nn-th planet →→ take-off from the nn-th planet →→ landing to the 11-st planet →→the 11-st planet.

The mass of the rocket together with all the useful cargo (but without fuel) is mm 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 11 ton of fuel can lift off aiai tons of rocket from the ii-th planet or to land bibi tons of rocket onto the ii-th planet.

For example, if the weight of rocket is 99 tons, weight of fuel is 33 tons and take-off coefficient is 88 (ai=8ai=8), then 1.51.5 tons of fuel will be burnt (since 1.5⋅8=9+31.5⋅8=9+3). The new weight of fuel after take-off will be 1.51.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 nn (2≤n≤10002≤n≤1000) — number of planets.

The second line contains the only integer mm (1≤m≤10001≤m≤1000) — weight of the payload.

The third line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000), where aiai is the number of tons, which can be lifted off by one ton of fuel.

The fourth line contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤10001≤bi≤1000), where bibi 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 109109 tons of fuel.

Output

If Natasha can fly to Mars through (n−2)(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−1.

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

The answer will be considered correct if its absolute or relative error doesn't exceed 10−610−6. Formally, let your answer be pp, and the jury's answer be qq. Your answer is considered correct if |p−q|max(1,|q|)≤10−6|p−q|max(1,|q|)≤10−6.

Examples

input

Copy

2
12
11 8
7 5

output

Copy

10.0000000000

input

Copy

3
1
1 4 1
2 5 3

output

Copy

-1

input

Copy

6
2
4 6 3 3 5 6
2 6 3 6 5 3

output

Copy

85.4800000000

中文题意:一共n个星球,主人公从地球出发,飞到最后一颗星球(第n颗),然后再从第n颗星球飞回地球(第一颗),在每个星球上降落和起飞所需要的燃料都不同,(假设星球间飞行不需要燃料)给出起飞或降落消耗燃料的计算公式,询问这趟旅程最少需要消耗多少燃料。

策略:显然飞船质量越小消耗的燃料越少,这样飞船开始的时候带的燃料就可以越少,这两种影响对答案的影响方向都是相同的,所以我们果断选择飞船质量小。最优策略是飞船最后在地球上降落时没有燃料剩余,用公式求出最后一次燃料质量,这样递归求解即可。

#include<bits/stdc++.h>
using namespace std;
typedef double ld;
int n;
ld m;
const int N = 1005;
ld a[N], b[N];

ld digui(int pos, ld m)
{
    if(pos<=1)
        return m;
	if (a[pos] <= 1 || b[pos] <= 1)
	{
		puts("-1");
		return -1;
	}
	m += m / (a[pos] - 1);
	m += m / (b[pos] - 1);
	return digui(pos - 1, m);
}

int main()
{
	scanf("%d", &n);
	scanf("%lf", &m);
	for (int i = 1; i <= n; i++)
		scanf("%lf", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf("%lf", &b[i]);
	if (b[1] <= 1)
	{
		puts("-1");
		return 0;
	}
	ld no = digui(n, m / (b[1] - 1) + m);
	if (no == -1)
		return 0;
	if (a[1] <= 1)
	{
		puts("-1");
		return 0;
	}
	no += no / (a[1] - 1);
	printf("%.8f\n", no - m);
	return 0;
}

 

非线性功率放大器对QAM传输BER性能的影响及补偿 1、线性功率放大器对传输性能的影响 为表述非线性功率放大器对传输性能的影响,以Saleh模型进行观察。具体来说,在QAM调制器之后添加一个非线性模块,使调制后的波形经历AM / AM和AM / PM转换。 在Saleh模型中,转换用四个参数表示,即AM / AM转换为????a和????a,AM / PM转换为????p和????p。 在Saleh模型中,AM / AM和AM / PM方程以输入电压u的大小表示为: 式中,FAM / AM是AM / AM转换的输出电压与输入电压的关系,而FAM 阅读详情

相关推荐

别光看Demo了!用UE5 Lyra框架快速搭建你的多人对战游戏原型(含完整配置流程)

本文详细介绍了如何利用UE5 Lyra框架快速搭建多人对战游戏原型,包含完整的配置流程和实战案例。Lyra作为可直接二次开发的游戏模板,内置了GAS技能系统、Enhanced Input输入控制等核心功能,大幅缩短开发周期。通过替换角色模型、调整武器数值和配置新地图规则,开发者可在48小时内完成科幻团队竞技游戏原型的搭建。

weixin_28717411的博客 455

Codeforces Round #499 (Div. 2) 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 . ...

loooooog的博客 380

高通 Gen AI 推理扩展 (GENIE)(5):实战指南与Engine API深度解析

本文深入解析高通Gen AI推理扩展(GENIE)的Engine API核心功能与实战应用,涵盖引擎实例化、多引擎动态切换、性能调优及跨平台部署等关键技巧。通过详细代码示例和性能数据,帮助开发者高效利用GENIE进行AI推理,提升应用性能与稳定性。

weixin_29065959的博客 464

Codeforces Round #499 (Div. 2) C Fly题解

题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land onn−2n−2intermediate planets. Formally: w...

weixin_30785593的博客 199

LabVIEW多界面应用开发:从启动器到主界面的切换架构与实现

在图形化编程领域,模块化与界面管理是构建复杂应用程序的核心。其原理在于通过清晰的程序架构,实现不同功能模块间的独立运行与协同工作,从而提升代码的可维护性和可扩展性。这种架构的技术价值在于能够有效管理应用程序的生命周期与资源,避免内存泄漏,并确保流畅的用户体验。在测控系统、自动化测试等工程实践中,常需实现如启动界面选择语言或模式后,无缝切换至主功能界面的场景。本文聚焦于LabVIEW环境,深入探讨如何利用动态调用、状态机等机制,并结合功能全局变量(FGV)与队列消息处理器(QMH)等热词技术,构建健壮的多界面

weixin_30802819的博客 262

Spring WebFlux响应式编程实战(三):优雅处理异常与高效调试技巧

本文深入探讨了Spring WebFlux响应式编程中的异常处理与调试技巧。文章通过电商订单流处理场景,详细解析了Reactor核心操作符onErrorReturn、onErrorResume和onErrorMap的实战应用,并介绍了如何构建@ControllerAdvice和WebExceptionHandler全局异常处理防线。同时,提供了使用.log()操作符、Hooks.onOperatorDebug()及BlockHound进行高效调试的方法,旨在帮助开发者构建健壮、可维护的响应式应用。

weixin_29252171的博客 65

Codeforces Round #499 (Div. 2) 1011 C. Fly 二分

C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Natasha is going to fly on a rocket to Mars and return to Earth. Also, on t...

qq_36996464的博客 632

DaVinci Developer中枚举类型变量的创建与实战应用

本文详细介绍了在DaVinci Developer中创建和使用枚举类型变量的方法与实战应用。通过智能温控系统的案例,阐述了枚举类型在嵌入式开发中的核心价值,包括提升代码可读性、类型安全性和维护便捷性。文章还提供了枚举类型在状态机实现和多模块协同中的高级应用技巧,以及调试与优化的实用建议。

ik678901234的博客 511

Stages (水题压压惊)

Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be des...

鸿杰 的博客 404

重访时间与覆盖分析的stk操作

1.打开stk 2.创建一个新的场景,命名为Test,选择地球为场景星球,若为金星,可在Central Body里选择Venus(金星自转周期慢,自转周期243天,卫星轨道变化不明显)(其中start stop时间可设置长一些) 3.插入一个AreaTarget或者place,以AreaTarget为例 选择Pattern,Add三个点(用法可见前面的博客,有时候编程的代码也可以帮助理解stk的操作) 4.插入Satellite,选择Orbit Wizard(若想设置卫星的六根数也可

weixin_42664107的博客 1万+

DCDC系列(一): COT DCDC基本原理

电流环DCDC属于双环控制模式,根据电流检测的位置,分为峰值电流环控制模式、谷值电流环控制模式和平均电流环控制模式,主要由输出电压反馈环和电流环两个环路来实现控制,其瞬态响应比电压环更好,且有自动限流的功能,但仍需要斜坡补偿网络,且对噪声敏感。Stage3: 在下管NMOS打开阶段,由于后级负载此时间段内消耗的电量较少,所以VFB还未低至Vref,所以此阶段中,上管PMOS和下管NMOS均处于关断状态,此时的电感电流为0mA,此阶段测的VSW上的电压就是Cout上的电压VREG;

weixin_40073649的博客 3938

1011A - Stages

A. Stages time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Natasha is going to fly to Mars. She needs to build a rocket, which cons...

memory_qianxiao的博客 435

基于咸鱼最新九宫格图标验证码的语义增强模型识别

本文探讨了破解复杂验证码的技术思路,重点分析了某平台的九宫格验证码应对策略。作者提出通过图像语义抽取和增强技术来扩充数据集:先采集少量真实样本,利用形态学操作进行前增强生成变形图像,再通过叠加背景噪声进行后增强。同时强调真实数据集的重要性,建议采用真实+生成数据的混合训练方法。实验表明该方法可使模型准确率达到95%以上,但作者特别声明本文仅供技术研究,严禁用于非法用途。

码王吴彦祖的博客 601

Codeforces 1010A - Fly

链接:Codeforces 1010A - Fly 大意:从地球飞到火星要经过n-2个星球,最后返回地球则是直接返回,每个星球起飞和降落都需要燃料,且效率不同。已知火箭自重为m,星球数n(包括地球和火星),以及每个星球起飞降落时的燃料效率ai和bi,求出发时需携带的最小燃料量,若不可行,输出-1。(2&lt;=n&lt;=1000,1&lt;=m,ai,bi&lt;=1000) 思路:最优解显...

淡泊明志,宁静致远 685

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

CodeForces - 1010A 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 ...

ling_wang的博客 878

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

「Codeforces 1010A」Fly - 二分答案

建议访问原文出处,获得更佳浏览体验。 原文出处:https://hyp1231.github.io/2018/07/28/20180728-cf1010a/ 题意 有 nnn 个行星,标号 1∼n1∼n1\sim n。飞行器从 111 出发,经过 2,3,…,n−12,3,…,n−12,3,\ldots, n-1 到达 nnn,再从 nnn 出发到达 111。 飞行器重 mmm 吨,且其携...

hyp1231的博客 462

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Codeforces contest 1010 problem A 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 . ...

天翼之城的博客 205

【杂题】Codeforces499Div1 CF1010A Fly

题意: 娜塔莎(红*?)是个宇航员,她要用一支火箭在n个行星上依次降落,起飞。 在每个行星,有一个起飞的燃料效率,和降落的燃料效率 设火箭在某次行动前,自重以及燃料重量之和为mmm,效率为ppp,消耗的燃料为lll,满足l∗p=ml∗p=ml*p=m 现在求从1号行星起飞,绕完一圈再回来所需要的最小燃料总数。 分析: 二分做这题也可以,只不过限定次数比较好。 不过更好的方法是...

氧化钠的博客 316

CodeForces - 1011C Fly【数学or二分】

题目链接:http://codeforces.com/problemset/problem/1011/C 题目大意:有n个星球,顺序编号,1为出发点-地球,n为目的地-火星,现在要顺序登陆以及离开这n个星球(最后从火星飞回地球),其中着陆和离开每个星球需要消耗一定的燃料。问你从地球最少带多少燃料可以顺利完成飞行飞回地球。 输入n为n个星球,m为火箭的裸重量,接下来两行 第一行ai表示第i个星球上1...

Gina_h的博客 359

7-27 Codeforces Round #499 (Div. 2)

C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search 、math。 题意:总共有n个星球,飞船从地球起飞经过n-2个星球(在每个星球上做降落、起飞的动作)到达火星,在火星上同样降落起飞,然后直接返回地球做降落。每个星球起飞所需的燃料质量为ai,降落所需要的燃料质量为bi...

weixin_30797027的博客 69

Codeforces Round #499 (Div. 2)

A - Stages Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of lette

qq_45772483的博客 247

codeforces 1010A(二分答案)

题意描述 火箭自身的重量为m,每次从第i个星球起飞的系数为a[i],从第i个星球降落的系数为b[i],飞行路线为1起飞-2降落-2起飞-3降落-n降落-n起飞-1降落,如果火箭携带的燃料重量为x,则每次起飞降落花费的燃料为(x+m)/系数。询问可以使火箭完成飞行路线所需要的最少重量的燃料,如果不能完成,则输出-1 思路 这道题很明显是二分答案,check函数需要判断的是x+m吨的燃料最后结束飞行后剩余的重量是否大于m,最后二分结束后还需要再判断一下二分后的答案是否符合条件,如果不符合就输出-1。这道题还有一

Dejavu的博客 493

Codeforces Round #499 (Div. 2) C题 二分

 Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the...

路漫漫其修远兮,吾将上下而求索 568

C-FLY(思维+数学)CodeForces 1011C

题目:http://codeforces.com/problemset/problem/1011/C 题意:给你一个飞船,你从地球到火星再回来,已知飞船的重量和每个星球起飞和落下1吨燃料能支持多少重量的飞船起飞,求出最少需要的燃油的质量。 思路:这个题要从后往前推,设 火箭加燃油的总质量为x,燃油的质量为y,那么, x+y/a[i]=y,得到y=x/(a[i]-1) #include &amp;l...

莉莉莉的博客 535

Codeforces Round #499 (Div. 2) C Fly

Chat: 本来想随便看看题写一下, 发现自己现在理解能力跌倒谷底orz。 看了好久才看懂这个题是个什么意思。。。 Description: 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−2n−2 intermediate...

这是一个正经的RR 【Seriously 397

Codeforces Round #499 (Div. 2) C. Fly(思维)

  题目链接:CodeForces 1011C Fly        题意是有n个星球,1代表地球,然后输入一个m表示火箭的重量,然后输入了两组n个数,第一组表示在每个星球起飞时消耗一吨燃料的质量数,a[i]就表示每a[i]吨就要消耗1吨燃料,第二组就表示在每个星球降落时消耗一吨燃料的质量数,然后问当火箭从1飞到2到3....到n星球后又返回1星球最少需要加多少燃料。        暴力枚举...

Charles_Zaqdt的博客 413
上一篇: codeforces-1009D Relatively Prime Graph
下一篇: 牛客练习赛25 D 贝利福斯数
「已注销」
博客等级 码龄9年 6粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值