fork download
  1. library(gtools)
  2.  
  3. FindMin <- function(a) {
  4. n <- length(a)
  5. if (n <= 1) return(a[1])
  6. r <- binsearch(function(i) sign(a[i] - a[i - 1]), c(2, n))
  7. if (r$flag %in% c("Between Elements", "Found")) return(a[r$where[1]])
  8. return(min(a[1], a[n]))
  9. }
  10.  
  11. PrintMin <- function(a) {
  12. cat("入力: "); cat(a, sep = ", "); cat("\n")
  13. cat("出力: "); cat(FindMin(a)); cat("\n")
  14. cat("\n")
  15. }
  16.  
  17. PrintMin(c(115, 109, 107, 101, 92, 85, 76, 66, 65, 62, 53, 49, 40, 38, 35, 25, 23, 17, 9, 2, 0, 5, 8, 10, 11, 20, 30, 37, 42, 47))
  18. PrintMin(c(110, 104, 96, 93, 84, 83, 87, 93, 98, 103, 113, 120, 121, 128, 133, 134, 142, 152, 159, 169, 171, 174, 183, 186, 196, 203, 210, 212, 221, 224))
  19. PrintMin(c(138, 135, 127, 124, 122, 112, 103, 98, 92, 87, 77, 73, 71, 63, 59, 51, 41, 36, 45, 54, 63, 71, 81, 88, 90, 98, 105, 112, 114, 119))
Success #stdin #stdout 0.23s 39572KB
stdin
Standard input is empty
stdout
入力: 115, 109, 107, 101, 92, 85, 76, 66, 65, 62, 53, 49, 40, 38, 35, 25, 23, 17, 9, 2, 0, 5, 8, 10, 11, 20, 30, 37, 42, 47
出力: 0

入力: 110, 104, 96, 93, 84, 83, 87, 93, 98, 103, 113, 120, 121, 128, 133, 134, 142, 152, 159, 169, 171, 174, 183, 186, 196, 203, 210, 212, 221, 224
出力: 83

入力: 138, 135, 127, 124, 122, 112, 103, 98, 92, 87, 77, 73, 71, 63, 59, 51, 41, 36, 45, 54, 63, 71, 81, 88, 90, 98, 105, 112, 114, 119
出力: 36