编程介的小学生 2019-12-31 18:40 采纳率: 0.2%
浏览 43

Prison Break 风险问题

Problem Description
To save Sara, Michael Scofield was captured by evil policemen and he was arrested in Prison again. As is known to all, nothing can stop Michael, so Prison Break continues.
The prison consists of many circular walls. These walls won't intersect or tangent to each other.

Now Michael is arrested in one of the deepest rooms, and he wants to know how many walls he has to break at least for running out. In figure 1, Michael has to break 3 walls at least and in figure 2, 2 walls are needed.

Input
There will be multiple test cases (no more than 10) in a test data.
For each test case, the first line contains one number: n (1<=n<=50,000) indicating the total number of circular walls.
Then n lines follow, each line contains three integers x, y, r. (x,y) indicates the center of circular wall and r indicates the radius of the wall.
-100,000<=x,y<=100,000
1 <= r <= 100,000
The input ends up with EOF.

Output
The least number of walls to break for running out.

Sample Input
3
0 0 1
0 0 2
0 0 3
3
0 0 10
5 0 1
-5 0 1

Sample Output
3
2

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 09:26
    关注

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

    # read data
    data <- read.table(header = TRUE, text = stdin())
    
    # convert coordinates into vectors
    data$x <- as.numeric(data$x)
    data$y <- as.numeric(data$y)
    
    # calculate the number of walls to break
    breaks <- function(x, y, r){
      # calculate distance between points
      dist <- sqrt((x - y)^2 + (r^2))
      
      # count the number of walls that need to be broken
      breaks <- ceiling(dist / r)
      
      return(breaks)
    }
    
    # run the loop on all data points
    results <- lapply(data$x, function(x) {
      results[[paste0("x", x)] <- lapply(data$y, function(y) {
        results[[paste0("x", x)] <<- breaks(x, y, 1)]
      }) 
    })
    
    # print results
    print(results)
    

    This code reads in the data from standard input, converts the coordinate values into numeric vectors, calculates the distance between each pair of points using the Euclidean distance formula, counts the number of walls that need to be broken based on this distance, and outputs the result for each data point.

    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上