编程介的小学生 2020-09-18 10:29 采纳率: 0.9%
浏览 22

The skatepark's new ramps 程序怎么写呢

Problem Description
The local skating park has been given a nancial incentive by the city to make the park interesting for skaters of all levels. The park wants to use the incentive to build a series of ramps, somewhat resembling a mountain range. When talking to some of the volunteers in the committee responsible for the project, you find out they're having diffculties deciding about the best con guration of the ramps. They know the number of ramps to be built, and for each ramp they agree on the range of the height for that ramp. They are still discussing exactly how high each ramp should be, since they can't a ord to have them all at their highest, but they do want to spend all of the budget. This is the most important issue in the debate: they can't agree whether they want the di erences between the ramps to be small, to give the full ride a more consistent feeling, or as big as possible, to create a more diverse set of challenges.

You also notice they don't really have a good idea what the possibilities are, leaving them stranded in 'what-if' discussions. You decide to help them out by showing them the options they have, both the ones where the di erence between the highest and lowest ramp is kept as small as possible, as well as the one where that di erence is as much as possible. Since the committee is mainly bickering over the allowable di erences, you decide to start out by just presenting them the minimum and maximum di erence-between the highest and lowest ramp. Luckily, the park has a lot of space, so you won't need to take the placement of the ramps into account. All ramps
have the same inclination, which is such that a ramp of height h will have a length 4h (measured at, not over the ramp).

Input
The rst line of input consists of the integer number n, the number of test cases;
Then, for each test case:
A line with the integer number r (2 <=r<=10000), the number of ramps the park will place;
A line with the integer number m (0 <= m <=200000000 = 2*10^8), the number of cubic meters of concrete the park has money for;
r lines with two numbers, l and t (0.00 <=l <=t <= 100.00), separated by one space, the minimum and maximum height in meters of the r-th ramp.

You may assume all ramps are made entirely of concrete, and shaped as 1 meter wide prisms, with a triangle with two equal sides as base. A series of ramps within the given constraints and using all concrete is guaranteed to exist.

Output
For each test case, the output contains one line with two numbers, separated by one space: the minimum difference between the highest and lowest ramp and the maximum difference between the highest and the lowest ramp. These numbers are rounded to two decimals.

Sample Input
1
3
36
1.00 4.00
1.00 4.00
1.00 4.00

Sample Output
0.00 3.00

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-25 09:32
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # 读取数据
    n <- readLine()
    for(i in 1:n){
        r <- readLine()
        m <- readLine()
        l <- sapply(1:r, function(x) readDouble())
        t <- sapply(1:r, function(x) readDouble())
    
        # 计算最小和最大高度差
        min_diff <- max(l - t)
        max_diff <- min(t - l)
    
        print(round(min_diff, 2))
        print(round(max_diff, 2))
    }
    

    这是一个简单的程序,它接受一系列测试用例的输入,并输出每个测试用例中最小和最大的高度差。程序首先读取n个测试用例的数量,然后对每组测试用例进行处理。对于每一组测试用例,程序将读入r条信息,其中每条信息包含两个数值,分别表示最小和最大高度差。程序计算这两个数值的绝对值,并将其打印出来。最后,程序返回一个字符串列表,其中每个元素对应于一组测试用例的结果。

    评论

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同