墓后煮屎人 2022-03-23 15:15
浏览 32
已结题

今天iOS面试一道算法题被虐了,还请算法niu人分析一二(英语渣,好像叫多级火箭)。

Many rockets are made up of several stages to increase efficiency. When the fuel in one stage burns up, the stage can be discarded, reducing the weight of the remaining rocket. The first stage needs a strong engine capable of lifting the whole rocket, while later stages can have smaller engines.
In this problem, you will determine which stages to put together to maximize the upward velocity of the rocket when all the fuel has burned.
For each stage, you will be given:
• the mass S of the stage, in kilograms, when it is empty (without fuel),
• the mass L of the fuel, in kilograms, in the stage,
• the thrust T , in newtons, provided by the engine in the stage, and
• the fuel consumption C, in kilograms per second, of the stage.
Assume that the rocket points straight upward for the duration of the flight. Two forces act on the rocket: the force of the engine, which is T newtons upwards, and the force of gravity, which is 9.8 M newtons downwards, where M is the total mass of the rocket in kilograms, including fuel. The acceleration of the rocket is F divided by M metres per second per second upwards, where F is the total net force acting on the rocket in newtons, and M is the total mass of the rocket in kilograms, including fuel. As soon as a stage finishes burning, it is immediately discarded and the next stage starts to burn. The final velocity of the rocket is the integral of the net acceleration (due to gravity and the engine) over time.
Due to safety regulations, the net acceleration of the rocket is never allowed to be downwards, until the rocket runs out of fuel.
Also due to safety regulations, the total mass of the rocket cannot exceed 10000 kilograms. The rocket must have at least one stage.

Input
The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing an integer N, the number of rocket stages in the current test case. There will be no more than 1000 stages. This line is followed by N lines, one for each stage. Each of these lines contains the four integers S, L, T, C that describe a stage, as explained above. Each of these integers can be represented by a 32-bit unsigned binary number. The order of the stages as listed must be preserved but some stages (including, possibly, the first stage) may be left out of the rocket. The stage listed first is at the top of the rocket (and will burn last).
For every test case in the input, it is always possible to construct at least one rocket satisfying all the requirements of the problem statement.

Output
For each test case, output a line containing a single integer, the maximum possible speed in metres per second of the rocket when it has finished burning, rounded to the nearest metre per second.
Sample Input

1
9999 1 1000000 1

Sample Output

90

-

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 3月31日
    • 创建了问题 3月23日

    悬赏问题

    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)