编程介的小学生 2019-12-31 17:46 采纳率: 0.2%
浏览 49

Enchantress 程序的代码

roblem Description
This time Vance controls a hero, enchantress and let's just called her Aiushtha. Aiushtha uses spear to attack and she has a powerful ultra skill called Impetus.
It will give your enemy huge damage every time you attack.
The damage equals to p*dis, p is constant decimal, and dis means the distance between you and your enemy when the spear hit your enemy.

Now Vance's enchantress is run after her enemy, to make the problem simple,
let's imagine that you and your enemy can only run left or right.
Your enemy will always run left and Aiushtha can turn around at any time.
Aiushtha can't go to the leftside of your enemy.

The firing range of enchantress is d, a.k.a. you cannot attack if the distance between you and your enemy if longer than d.
She can't attack twice within cd seconds. Your enemy speed is v1, your speed is v2, and your spear's speed is v3.
We guarantee that v3 > max(v1,v2). The enemy's current life point is hp.
When enchantress uses impetus to hurt his enemy, the enemy's life reduce the value of the damage that impetus makes.
In time t=0s your enemy is at x=0 and you are in x=d,
your enemy will always run leftwards now Aiushtha finds that she has only two spears and she want to kill his enemy as soon as possible. Can you help her?

Input
The first line contains a single positive integer T( T <= 200 ), indicates the number of test cases.
For each test case: give you the parameters separated by a single space in the following order: d, cd, v1, v2, v3, hp, p.
All of above numbers are positive decimals between 0 and 10^6 and we guarantee that cd is longer than the time the spear need to hit the enemy.
When the enemy's current hp is equals or lower than zero he died immediately. All of the given numbers have at most two decimals.

Output
For each test case: output the case number as shown and then output the least time needed to make the enemy die up to 4 decimals.
If it's impossible to kill the enemy output -1.

Sample Input
2
600 2 400 300 1000 2000 0.5
600 2 400 300 1000 200 0.5

Sample Output
Case #1: -1
Case #2: 1.0000

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 11:31
    关注

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

    # Import necessary packages
    library(tidyverse)
    
    # Define function for calculating the damage
    damage <- function(dis, cd, v1, v2, v3) {
      return(dis * (v1 + v2))
    }
    
    # Function to calculate the least time required to kill the enemy
    least_time_to_kill <- function(d, cd, v1, v2, v3, hp, p) {
      # Initialize variables
      total_damage <- 0
      time_left <- cd
      
      # Check if the enemy's life points are greater than 0
      while (hp > 0) {
        # Calculate the damage from the last attack
        last_damage <- damage(dis = d, cd = cd, v1 = v1, v2 = v2, v3 = v3)
        
        # Subtract the damage from the enemy's life points
        hp -= last_damage
        
        # Update the total damage
        total_damage += last_damage
        
        # Check if there are more than one spear remaining
        if (length(spears) == 2) {
          # Calculate the new time left based on the remaining time and the spear's speed
          time_left -= ((d / (v3 + v2)) / v2)
          
          # Add the time left to the total time
          total_time <- total_time + time_left
        }
      }
      
      # Return the least time required to kill the enemy
      return(min(c(total_time, Inf)))
    }
    
    # Main function to solve the problem
    solve_problems <- function() {
      # Read input data from stdin
      input <- readLines(stdin())
      
      # Initialize variables
      num_cases <- ncol(readLines(stdin()))
      total_time <- numeric(num_cases)
      spears <- c()
      
      # Solve each test case
      for (case_num in 1:num_cases) {
        # Get the parameters for this test case
        params <- strsplit(input[case_num], " ")[3]
        
        # Split the parameters into components
        d <- as.numeric(strsplit(params, " ")[1])
        cd <- as.numeric(strsplit(params, " ")[2])
        v1 <- as.numeric(strsplit(params, " ")[3])
        v2 <- as.numeric(strsplit(params, " ")[4])
        v3 <- as.numeric(strsplit(params, " ")[5])
        hp <- as.numeric(strsplit(params, " ")[6])
        p <- as.numeric(strsplit(params, " ")[7])
        
        # Find the number of spears available
        num_spears <- length(unique(c(d, cd)))
        
        # Check if it's possible to kill the enemy using the spears available
        if (num_spears < 2) {
          total_time[case_num] <- -Inf
        } else {
          # Determine the least time required to kill the enemy
          total_time[case_num] <- least_time_to_kill(d, cd, v1, v2, v3, hp, p)
        }
        
        # Store the result for this test case
        spears[case_num] <- num_spears
      }
      
      # Print the results
      print(tibble(case_num = 1:num_cases,
                   time = total_time))
    }
    
    # Call the main function
    solve_problems()
    

    This R code defines a least_time_to_kill function that calculates the least time required to kill an enemy using a specified set of parameters. The solve_problems function reads input data from stdin, solves each test case, and prints the results.

    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上