编程介的小学生 2020-01-26 17:51 采纳率: 0.4%
浏览 120

Two Mirrors 镜子的问题

Problem Description
Nomad wants to know why girls like using mirrors. So he bought one, but it's not a normal one. The mirror is made up of two normal mirrors, which are connected at a point (x2, y2). So it is said, two mirrors can be described as two line segment. (x1, y1) (x2, y2) and (x2, y2) (x3, y3). And Nomad is at the point (x0, y0). And he is amazing to see that there are many Nomads in the special mirror. The Kth Nomad is described as the picture below. (Mirror face is always on the side of the smaller angle, and three point of mirror are never in a line.)

The first Nomad is the image of Nomad
The second Nomad is the image of the first Nomad
The third Nomad is the image of the second Nomad
And continue to Kth Nomad~

The first Nomad is always in mirror(x1,y1)(x2,y2);
The second Nomad is always in mirror(x2,y2)(x3,y3);
The third Nomad is always in mirror(x1,y1)(x2,y2);
The 4th Nomad is always in mirror(x2,y2)(x3,y3);
And continue to Kth Nomad~

Input
There are multiple cases. For each test case, Nine numbers, x0, y0, x1, y1, x2, y2, x3, y3 and a integer K.(1 ≤ K ≤ 1000)

Output
If you can see Kth Nomad ,print a point x, y (accurate up to 4 decimal places.) where Kth Nomad is, or print "You can't see me!"(No quote).

Sample Input
0.0 0.0
-4.0 0
0.0 20.0
4.0 0
1
0.0 0.0
-4.0 0
0.0 20.0
4.0 0
2

Sample Output
-7.6923 1.5385
14.2012 5.9172

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-26 10:21
    关注

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

    # read input
    input <- readLines()
    
    # split into list
    lines <- unlist(strsplit(input[1], "\n"))
    
    # parse lines
    points <- lapply(split(lines, ","), function(x) c(parse.numeric(x)[1], parse.numeric(x)[2]))
    
    # get the mirror points
    mirror_points <- matrix(points[-c(1:2)], ncol=2, byrow=T)
    mirror_points[,1] <- mirror_points[,1] + 0.5 # make sure the middle is the same
    mirror_points <- mirror_points[mirror_points[,1] >= 0, ] # remove negatives
    
    # calculate the distance between each pair of points
    distances <- apply(mirror_points, 1, function(x) sqrt(sum((x - mirror_points)^2)))
    
    # sort distances
    sort_distances <- sort(distances)
    
    # find the kth element in sorted distances
    k <- ceiling(sort_distances[length(sort_distances)] * 2^(-4)) # rounding down for the nearest whole number
    
    # calculate the x and y coordinates of the kth element
    x <- mirror_points[k, 1]
    y <- mirror_points[k, 2]
    
    # output result
    cat(round(x, 4), " ", round(y, 4))
    
    评论

报告相同问题?